title: Comparing methods from MethodInfo and IMethodInvocation
body: <p>I am using aspect-oriented programing to implement logging system. So, when the method being invoked I intercepting that call and get to that function:</p>
  
  <pre><code>    private IEnumerable&lt;ILogMessage&gt; GetLogMessageFromAttribute(IMethodInvocation input)
      {
          List&lt;ILogMessage&gt; messages = new List&lt;ILogMessage&gt;();
          var t = input.Target.GetType();
          var method = t.GetMethods()
                      .FirstOrDefault(m =&gt; m.ToString() == input.MethodBase.ToString());
  
          if (method != null)
          {
              var attributes = method.CustomAttributes
                               .Where(atr =&gt; atr.AttributeType == typeof(LogAttribute));
  
              foreach (var atr in attributes)
              {
                  var logAttributeInstance =
                      (LogAttribute)Attribute.GetCustomAttribute(method, typeof(LogAttribute));
  
                  messages.Add(MethodInfoTools.FillParametersDataInLogMessage(method, input,
                      logAttributeInstance.LogMessage));
              }
          }
  
          return messages;
      }
  </code></pre>
  
  <p>Methods can to be compared by own name, but it can be overloaded and attribute can be different for these methods.</p>
  
  <pre><code>var method = t.GetMethods()
                  .FirstOrDefault(m =&gt; m.ToString() == input.MethodBase.ToString());
  </code></pre>
  
  <p>This way was good until I tried to intercept method with generic. In that case .ToString() returns:</p>
  
  <pre><code>System.String TestMethod2[String](System.Collections.Generic.IEnumerable`1[System.String], System.String)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>System.String TestMethod2[T](System.Collections.Generic.IEnumerable`1[System.String], T)
  </code></pre>
  
  <p>Is there some way to find out what exact method was executed?</p>