// 重写响应成员调用方法
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            // 获得真正的对象
            DynamicMetaObjectProviderImpl target = (DynamicMetaObjectProviderImpl)base.Value;
            Expression self         = Expression.Convert(base.Expression, typeof(DynamicMetaObjectProviderImpl));
            var        restrictions = BindingRestrictions.GetInstanceRestriction(self, target);

            // 输出绑定方法名
            Console.WriteLine(binder.Name + " 方法被调用了");
            return(new DynamicMetaObject(self, restrictions));
        }
Esempio n. 2
0
        /// <summary>
        /// 使用IDynamicMetaObjectProvider来实现动态行为
        /// </summary>
        public static void demoIDynamicMetaObjectProvider()
        {
            dynamic dynamicobj2 = new DynamicMetaObjectProviderImpl();

            dynamicobj2.CallMethod();
        }
 internal Metadynamic(Expression expression, DynamicMetaObjectProviderImpl value)
     : base(expression, BindingRestrictions.Empty, value)
 {
 }