title: How to wrap a static class in a non-static instance object (dynamically)
body: <p>I have an interesting problem.  I need to wrap static classes dynamically.  I.e. return a non-static instance to my callers. e.g.:</p>
  
  <pre><code>public object CreateInstance(string className) {
    Type t = assembly.GetType(className);
    if (IsStatic(t)) {
      return CreateStaticWrapper(t);
    } else {
      return Activator.CreateInstance(t);
    }
  }
  </code></pre>
  
  <p>So what I need is pointers as to how to implement <code>CreateStaticWrapper</code>.</p>
  
  <p>Note: I cannot use Dynamic objects unfortunately.</p>
  
  <p>So what are my options?  I'm not that keen on learning IL generation?  If IL generation (Reflection.Emit, or is there other ways now?) is the way to go does anyone have pointers there?</p>
  
  <p>Edit: It's important to note that I can return a Dictionary of Delegates.  So I could use <code>Delegate.CreateDelegate</code> for this but I can't seem to work out how to handle overloaded methods and Generic methods.</p>
  
  <p>Edit2: Another option would be to inject an empty constructor into the type using Emit, again any pointers? Is this even possible on a type marked as static? Does the static keyword make it into the IL?</p>
  
  <p>Edit3: For a bit of context, I'm passing this to a javascript environment see:  <a href="https://github.com/gatapia/js.net" rel="nofollow">my project</a>.  So I would like to be able to (in JavaScript):</p>
  
  <pre><code>var fileHelper = .create('System.IO.File');
  if (fileHelper.Exists(fileName)) { fileHelper.Delete(fileName); }
  </code></pre>
  
  <p>Thanks All.</p>