title: C# Changing class method at run-time
body: <p>I need to extend the behavior of an instance, but I don't have access to the original source code of that instance. For example:</p>
  
  <pre><code>/* I don't have the source code for this class, only the runtime instance */
  Class AB
  {
    public void execute();
  }
  </code></pre>
  
  <p>in my code I would to intercept every call to execute, compute some sutff and then call the original execute, something like</p>
  
  <pre><code>/* This is how I would like to modify the method invokation */
  SomeType m_OrgExecute;
  
  {
      AB a = new AB();
      m_OrgExecute = GetByReflection( a.execute );
      a.execute = MyExecute;
  }
  
  void MyExecute()
  {
      System.Console.Writeln( "In MyExecute" );
      m_OrgExecute();
  }
  </code></pre>
  
  <p>Is that possible?</p>
  
  <p>Does anyone have a solution for this problem?</p>