title: Run a method before all methods of a class
body: <p>Is it possible to do that in C# 3 or 4? Maybe with some reflection?</p>
  
  <pre><code>class Magic
  {
  
      [RunBeforeAll]
      public void BaseMethod()
      {
      }
  
      //runs BaseMethod before being executed
      public void Method1()
      {
      }
  
      //runs BaseMethod before being executed
      public void Method2()
      {
      }
  }
  </code></pre>
  
  <p>EDIT</p>
  
  <p>There is an alternate solution for this, make <code>Magic</code> a singleton and put your code on the getter of the static instance. That's what I did:</p>
  
  <pre><code>public class Magic
  {
  
      private static Magic magic = new Magic();
      public static Magic Instance
      {
          get
          {
              magic.BaseMethod();
              return magic;
          }
      }
  
      public void BaseMethod()
      {
      }
  
      //runs BaseMethod before being executed
      public void Method1()
      {
      }
  
      //runs BaseMethod before being executed
      public void Method2()
      {
      }
  }
  </code></pre>