Retrieving annotated method from attribute constructor
<p>If I annotate a method of a class with an attribute, I can then retrieve custom attributes for that class and see if it has that attribute or not. For example, I'm building a message-oriented program so I have classes like</p>

<pre><code>public class ErrorHandler
{
  [HandleMessage(ErrorHandling.ERROR)]
  private static void OnError(string message, object context, params object[] args)
  {
    Exception e;
    args.Extract(out e);

    Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace);
  }
}
</code></pre>

<p>At runtime I can do this:</p>

<pre><code>public static void RegisterStaticHandlers(Type type)
{
  foreach (var mInfo in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static))
  {
    var mAttr = mInfo.GetCustomAttribute&lt;HandleMessageAttribute&gt;();
    if (mAttr != null)
      RegisterInstanceHandler(mAttr.Message, mInfo.CreateDelegate&lt;MessageHandler&gt;());
  }
}
</code></pre>

<p>(I have some extension methods to simplify the code, they're not relevant now.)</p>

<p>My question is: can I get rid of this <code>RegisterStaticHandlers</code> method altogether and register the handler in the attribute constructor?</p>

<pre><code>public class HandleMessageAttribute : Attribute
{
  public string Message { get; private set; }

  public HandleMessageAttribute(string message)
  {
    Message = message;

    Messages.RegisterInstanceHandler(message, ... method reference here ...);
  }
}
</code></pre>

<p>Is there a way to retrieve the method that is annotated by an attribute in the attribute constructor, instead of the opposite (and regular) way of having the method and getting its attributes?</p>

<p>[Edited]
I just realized that I can at least do this in the static constructor:</p>

<pre><code>static ErrorHandler()
{
  Messages.RegisterStaticHandlers(typeof(ErrorHandler));
}
</code></pre>

<p>This at least keeps the registration of a class inside that class, which is great as far as I'm concerned :)</p>
