title: C# - How to access instances of a particular type that are used in Func<int> delegate
body: <p>In Factory.Process(..) method, I want get hold of instances of MyClass that are being used in the lambda expression of the Func delegate. But, How? 
  Can someone help me find a way to do it.</p>
  
  <p>Edit: This is an artificial example that demonstates my need. My intention behind this approach is that, I want to keep track of (or subscribe to) all the MyClass objects that are used in the delegate definition. So that, I can recalculate my total value whenever any MyClass object value is changed. Please suggest as to how to go about to solve this.</p>
  
  <p>Note: Expression tree doesnt seem to help in my case because I cant modify my parameter type at this moment and it restricts the usage of my complex function definitions.</p>
  
  <pre><code>public class MyClass
  {
      public int Value;
  
      public MyClass(int value)
      {
          Value = value;
      }
  }
  
  public class TestClass
  {
      public void TestMethod()
      {
          var obj1 = new MyClass(10);
          var obj2 = new MyClass(20);
          Factory.Process(() =&gt; obj1.Value + obj2.Value);
      }
  }
  
  public static class Factory
  {
      public static void Process(Func&lt;int&gt; function)
      {
          var total = function.Invoke();
  
          // Here, apart from invoke, I want to access the all the instances of MyClass that are used in 'function'
          // but how do I get to obj1 and obj2 objects through the 'function' delegate?
      }
  }
  </code></pre>