title: Using Extension methods in RoslynPad
body: <p>I try to understand an extension method similar to this code</p>
  
  <pre><code>var p = new Person("Tim");   
  p.LastName = "Meier"; 
  
  // reader.Get&lt;bool&gt;("IsDerivat");
  var IsOlivia = p.Get&lt;bool&gt;("Olivia");   
  </code></pre>
  
  <p>This is my code inside <a href="http://roslynpad.net" rel="nofollow noreferrer">RoslynPad</a>:</p>
  
  <pre><code>public static class PersonExtensions
  {
      public static T Get&lt;T&gt;(this Person person, string name)
      {
          return (T)person.NewFirstName(name);
      }
  }
  
  public class Person
  {    
      public Person(string firstName)
      {
          this.FirstName = firstName;
      }
  
      public string FirstName {get; private set;}
      public string LastName {get; set;}
  
      public object NewFirstName(string name)
      {
          this.FirstName = name;
          return (object) this.FirstName;
      }        
  }    
  </code></pre>
  
  <p>But i get this error</p>
  
  <blockquote>
    <p>error CS1109: Extension methods must be defined in a top level static
    class; PersonExtensions is a nested class</p>
  </blockquote>
  
  <p>I found this question <a href="https://stackoverflow.com/questions/13071296/error-extension-methods-must-be-defined-in-a-top-level-static-class-cs1109">extension-methods-must-be-defined-in-a-top-level-static-class-</a> and the answers are good.</p>
  
  <p>Adding a <code>namespace Foo</code> returns </p>
  
  <blockquote>
    <p>error CS7021: Cannot declare namespace in script code </p>
  </blockquote>
  
  <p>It seems that roslynpad adds stuff behind the scene. 
  So how can i make sure that my extension method is defined in a top-level static class?</p>