static void Main(string[] args) { dynamic dynamicobj2 = new DynamicType2(); dynamicobj2.Call(); Console.Read(); }
// 重写响应成员调用方法 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) { // 获得真正的对象 DynamicType2 target = (DynamicType2)base.Value; Expression self = Expression.Convert(base.Expression, typeof(DynamicType2)); var restrictions = BindingRestrictions.GetInstanceRestriction(self, target); // 输出绑定方法名 Console.WriteLine(binder.Name + " 方法被调用了"); return(new DynamicMetaObject(self, restrictions)); }
internal Metadynamic(Expression expression, DynamicType2 value) : base(expression, BindingRestrictions.Empty, value) { }