title: Programatically insert line of code before end of method body
body: <p>What I wanna do is to programatically insert a line of code (<strong>C#</strong>, meaning open an existing file and write to it) (see below):</p>
  
  <p>I have <strong>MyClass.cs</strong>:</p>
  
  <pre><code>public class MyClass
  {
    public void HelloWorld()
    {
      //hello world
      switch(somevalue)
      {
        case derp:
        //do something here
        break;
      }
      &lt;--------INSERT CODE HERE --------&gt;
    }
  }
  </code></pre>
  
  <p>What is the best approach to doing this? How can I find the method "HelloWorld" and then find the "matching" closing bracket (<strong>}</strong>)?</p>
  
  <p>Many will probably wonder why I want this (since it seems kinda stupid). I want this because I'm writing a PostProcess-script for Unity when building for Windows Store Apps. And some things are required to be added manually after each new build (and I wanna make this automatically to minimize the amount of stuff that can go wrong/forgotten).</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Apparently I wasn't clear enough. 
  The above code is just an <strong><em>example</em></strong> meaning, it won't look exactly like the code example above. There may or may not be a switch case. There may be additional <code>{</code> and <code>}</code> characters (although there will always be a matching start and end bracket). There is no "placeholder", meaning there is no "<em>&lt;--------INSERT CODE HERE --------></em>" that I can just find and replace. If things were that easy I wouldn't be asking for help! Sorry if I was unclear, but I honestly thought I gave enough information.</p>