title: Best way to generate code in C# similar to using decorators?
body: <p>Say I have a pattern that I'm constantly repeating. Something like:</p>
  
  <pre><code>static class C {
    [DllImport("mydll")]
    private static extern uint MyNativeCall1(Action a);
    public static uint MyWrapper1(Action a) {
      // Do something
      return MyNativeCall1(a);
    }
  
    [DllImport("mydll")]
    private static extern uint MyNativeCall2(Action a);
    public static uint MyWrapper2(Action a) {
      // Do something
      return MyNativeCall2(a);
    }
  
    //...
  
    [DllImport("mydll")]
    private static extern uint MyNativeCallN(Action a);
    public static uint MyWrapperN(Action a) {
      // Do something
      return MyNativeCallN(a);
    }
  }
  </code></pre>
  
  <p>The only thing different in all those is the name of the native function and wrapper method. Is there a way to generate them via something like decorators? At first I thought C# attributes were decorators. That is, that I could generate the code via something like <code>[GenerateScaffolding("MyNativeCall1")]</code>. But it seems attributes are more like annotations, instantiating a class that holds some metadata. </p>
  
  <p>Neither does C# have macros. So is there any way to do this?</p>
  
  <p>A few things to keep in mind:</p>
  
  <ul>
  <li>The idea is that the wrapper methods have extra code; they are not merely calling the native functions.</li>
  <li>The idea is also that the generated code can be interleaved with other existing code inside a class and not to generate the class file itself; something like either decorators or C/C++ macros.</li>
  <li>The approach should not depend on any particular IDE. Specifically, I'm not on Visual Studio.</li>
  </ul>