Once you have a dynamic object, the compiler is least worried about any method calls that you could make for the dynamic object. Calls will only be allowed at run time. In this case, the Read () method is dispatched dynamically at run time.
More beautiful, C # now gives you the flexibility to determine how dynamic calls should be sent. You can implement IDynamicObject to write these binders yourself. For example, see how I create a dynamic reading class that allows you to call your own methods on an instance of this.
public class DynamicReader : IDynamicObject { public MetaObject GetMetaObject (System.Linq.Expressions.Expression parameter) { return new DynamicReaderDispatch (parameter); } } public class DynamicReaderDispatch : MetaObject { public DynamicReaderDispatch (Expression parameter) : base(parameter, Restrictions.Empty){ } public override MetaObject Call(CallAction action, MetaObject[] args) {
You can now use the dynamic keyword to create dynamic objects, like
dynamic reader=new DynamicReader(); dynamic data=reader.Read();
source share