title: What is the nicest way to dynamically implement an interface in C#?
body: <p>I often find it quite a distraction to have to implement an interface just because I need it once for some method call. I have to create a class somewhere else, implement the interface etc. etc.</p>
  
  <p>Java has a feature called <a href="http://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html">Anonymous Classes</a> that allows one to implement the interface "inline". My question is thus: what is the <em>nicest</em> way you can think of of accomplishing something similar in C# using existing syntax (and I realise that "nicest" is subjective). I'm looking for nice syntax, not necessarily performance.</p>
  
  <p>I implemented the following as POC in <strong>C#</strong>:</p>
  
  <p>Given</p>
  
  <pre><code>interface IFoobar
  {
     Boolean Foobar(String s);
  }
  
  IFoobar foo = Implement.Interface&lt;IFoobar&gt;(new {
     Foobar = new Func&lt;String, Boolean&gt;(s =&gt; s == "foobar")
  });
  </code></pre>
  
  <p>This uses an anonymous object and some reflection/emit to implement the <code>IFoobar</code> interface (overlooking properties, generic methods and overloading). But, I'm not a fan of the <code>new Func&lt;...&gt;</code> stuff but can't do without.</p>
  
  <p>Looking around I noticed a library called <a href="https://code.google.com/p/impromptu-interface/">Impromptu Interface</a>, but wasn't impressed by its syntax to support methods. </p>
  
  <p>Is there a "nicer" way?</p>
  
  <p><strong>Edit</strong>: I'm not looking for Java vs C# flame wars.</p>