title: Can I emit CIL inside an existing method?
body: <p>I need to change some basic calculations during the life-time of an object.</p>
  
  <p>I know how to create a dynamic method and call it through <code>delegate.Invoke</code>; however it is twice as costly as a static method call.</p>
  
  <p><strong>Is it possible to emit CIL inside an existing method?</strong></p>
  
  <p>Say one method calls another and the another can have different body (one at a time):</p>
  
  <pre><code>public void Worker()
  {
      while(true)
      {
          int a = queueA.Dequeue();
          int b = queueB.Dequeue();
  
          int c = Calculate(a,b);
      }
  }
  
  int Calculate(int a, int b)
  {
      // here goes dynamic code.
      // could be return a - b;
      // could be return b - a;
  }
  </code></pre>
  
  <p>Please note that the calculation logic in the example is greatly simplified.</p>