title: C#: How to create an attribute on a method triggering an event when it is invoked?
body: <p>Is there a way in C# or .NET in general to create an attribute on a method which triggers an event when the method is invoked? Ideally, I would be able to run custom actions before and after the invocation of the method.</p>
  
  <p>I mean something like this:</p>
  
  <pre><code>[TriggersMyCustomAction()]
  public void DoSomeStuff()
  {
  }
  </code></pre>
  
  <p>I am totally clueless how to do it or if it possible at all, but <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx" rel="noreferrer">System.Diagnostic.ConditionalAttribute</a> might do a similar thing in the background. I am not sure though.</p>
  
  <p><strong>EDIT</strong>: I forgot to mention that due to the circumstances of my specific case, performance is not really an issue.</p>