How can i effectively write the code for calling a function before and after execution of every function in a class.
-
I already have very large amount of code . Now I want to integrate one more functionality for this code for which i have to execute some code before and after every function call .How can i do this effectively.
-
I already have very large amount of code . Now I want to integrate one more functionality for this code for which i have to execute some code before and after every function call .How can i do this effectively.
This is a complicated topic, and one you really should have designed for before you reached this point. Normally, you would apply something called Aspect Oriented Programming (AOP) to allow you to automatically add code to your application at specified points. This gives you fine grained control of what you want to do. As you haven't designed your application for this, you're probably going to have to fall back to a technique called IL weaving - this means that you are going to weave in IL code to your application (it's what most AOP systems do, but they give you control over the process - you're going to end up having to manually do this yourself). You will probably find this[^] article to be some help in getting started.
This space for rent
-
I already have very large amount of code . Now I want to integrate one more functionality for this code for which i have to execute some code before and after every function call .How can i do this effectively.
[logging - How can I add a Trace() to every method call in C#? - Stack Overflow](https://stackoverflow.com/questions/559148/how-can-i-add-a-trace-to-every-method-call-in-c) (See reference to "PostSharp")
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
I already have very large amount of code . Now I want to integrate one more functionality for this code for which i have to execute some code before and after every function call .How can i do this effectively.
There are many ways to do this. However it depends how good your design and coding technique.
-
I already have very large amount of code . Now I want to integrate one more functionality for this code for which i have to execute some code before and after every function call .How can i do this effectively.
In addition to the CP article that Pete cited, also see: [^], [^].
«When I consider my brief span of life, swallowed up in an eternity before and after, the little space I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which know me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then.» Blaise Pascal
-
In addition to the CP article that Pete cited, also see: [^], [^].
«When I consider my brief span of life, swallowed up in an eternity before and after, the little space I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which know me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then.» Blaise Pascal
Thank you very much BillWoodruff .Can you please tell em how to pass our own custom attributes .
-
Thank you very much BillWoodruff .Can you please tell em how to pass our own custom attributes .
Question: what is the scale/scope of the code base you wish to monitor/log ? Multi-threading involved ? Team project with multiple code repositories ? Also see this recent article: [^].
yeswanthkumar wrote:
Can you please tell em how to pass our own custom attributes
While I am a registered owner of PostSharp, I do not have the expertise to comment on any other method/tool, and I have never tried to explore creating custom attributes in PostSharp: however their documentation/support are very good, and I expect if the need arose, it could be done: [^]. imho, the task of IL-weaving/AOP is an extremely technically deep subject, and experimenting with "rolling your own" potentially risky in terms of technical "cost." Have you looked at Spring.NET: [^] ? cheers, Bill
«When I consider my brief span of life, swallowed up in an eternity before and after, the little space I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which know me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then.» Blaise Pascal