Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Absolutely. Either implement <a href="http://msdn.microsoft.com/en-us/library/system.dynamic.idynamicmetaobjectprovider(VS.100).aspx" rel="noreferrer"><code>IDynamicMetaObjectProvider</code></a> or derive from <a href="http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject(VS.100).aspx" rel="noreferrer"><code>DynamicObject</code></a> for a much simpler route. See the <a href="http://dlr.codeplex.com/Wiki/View.aspx?title=Docs%20and%20specs" rel="noreferrer">DLR documentation</a> for some good examples.</p> <p>Here's a quick example of <code>DynamicObject</code>:</p> <pre><code>using System; using System.Dynamic; public class MyDynamic : DynamicObject { public override bool TryInvokeMember (InvokeMemberBinder binder, object[] args, out object result) { Console.WriteLine("I would have invoked: {0}", binder.Name); result = "dummy"; return true; } public string NormalMethod() { Console.WriteLine("In NormalMethod"); return "normal"; } } class Test { static void Main() { dynamic d = new MyDynamic(); Console.WriteLine(d.HelloWorld()); Console.WriteLine(d.NormalMethod()); } } </code></pre> <p><strong><code>&lt;plug&gt;</code></strong></p> <p>I have a bigger example of <code>DynamicObject</code> in the <a href="http://manning.com/skeet2" rel="noreferrer">2nd edition of C# in Depth</a> but I haven't yet implemented <code>IDyamicMetaObjectProvider</code>. I'll do so before the book's release, but the early access edition only has the <code>DynamicObject</code> example at the moment. Btw, if you buy it today it's half price - use the code <strong>twtr0711</strong>. I'll edit this answer later on to remove that bit :)</p> <p><strong><code>&lt;/plug&gt;</code></strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload