title: Is there way to know through reflection that a method is from caller's assembly?
body: <p>Let's consider the following code :</p>
  
  <pre><code>internal class FooInternal
  {
      internal static void DoIt()
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>Now i have a library inside which it is reflecting the <strong>FooInternal</strong> type and for a reflected methodInfo (in this case DoIt) i have this :</p>
  
  <pre><code>if ((methodInfo.Attributes &amp; MethodAttributes.FamANDAssem) == MethodAttributes.FamANDAssem)
  {
       // hits here.
  }
  </code></pre>
  
  <p>We can see that i am hitting the line for an internal method that is marked as FarmAndAssem. Now, I also need to ensure that the method is delared in the same assembly from where it is invoked so that my libary does not end up hitting the line for members from type defined in other assembly and marked as internal.</p>
  
  <p>I can't use Assembly.GetExecutingAssembly from within the library that reflects the method as it will return the assembly where the library resides not the assembly where type the is declared / invoked using the library.</p>
  
  <p>Therefore, the code should ensure the following workflow:</p>
  
  <pre>
   Given: FooInternal is declared in the same asssembly as the caller's assembly. 
   When: Called with MyLib.Fake(typeof(FooInternal)); 
   Then: It will hit the expected line.
  </pre>
  
  <pre>
   Given: A third-party type. 
   When: Called with MyLib.Fake(typeof(FileInfo)); 
   Then: It will not hit  the expected line even though *FileInfo* 
   has internal methods and as such the first condition passes, because 
   FileInfo belongs to a different assembly from caller's.
  
  </pre>