Adding code to the beginning / end of methods in runtime dynamically
        Posted  
        
            by Irchi
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Irchi
        
        
        
        Published on 2010-03-17T11:41:32Z
        Indexed on 
            2010/03/17
            11:51 UTC
        
        
        Read the original article
        Hit count: 243
        
I know instrumentation is a technique to add trace code dynamically into the methods to enable tracing and debugging.
I was wondering if this is only a "Trace" option, hard coded into the CLR to add only trace code, or is there the ability to add any code to the methods?
For example, I want to check for a condition in the beginning of every single method call in a certain class (say for permissions). Can I do this via adding dynamic code to the beginning of the methods in execution time?
I'm not sure how this trace "instrumentation" thing works, but I'm wondering if this can be used for other goals too, or not.
© Stack Overflow or respective owner