Lets say in .NET/C# I have a bunch of static classes in a namespace. I don't want to manually change the code but I'd like to make them all call a specific function when entering a function. It would be nice if I could pass in the class/function name but not required. How might I do this?
-
Is this for analytical purposes or a permanent thing?500 - Internal Server Error– 500 - Internal Server Error2013-02-03 04:05:34 +00:00Commented Feb 3, 2013 at 4:05
-
@500-InternalServerError: Not my call but probably a permanent thing if functions/classes can be filtered outuser34537– user345372013-02-03 16:41:44 +00:00Commented Feb 3, 2013 at 16:41
Add a comment
|
2 Answers
You are looking for something called Aspect Oriented Programming or AOP.
Try the PostSharp library
2 Comments
Sam Axe
That's all i've got as far as libraries. If you don't like that option then you can always write something to modify the code or the IL yourself.
If you want to do this without modifying the source code, you will be looking at modifying the IL directly. In fact, "PostSharp" itself does rewrite your assembly IL, as do many aspect-oriented libraries.
You could theoretically rewrite your the IL yourself, (and a project such as Cecil might help) without modifying the source - however, I doubt it would be worth the effort.