Esempio n. 1
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
        {
            //
            // Demand Full Trust to proceed with the binding.
            //

            new PermissionSet(PermissionState.Unrestricted).Demand();

            ComMethodDesc method;
            var           target = _callable.DispatchComObject;
            var           name   = _callable.MemberName;

            bool holdsNull = value.Value == null && value.HasValue;

            if (target.TryGetPropertySetter(name, out method, value.LimitType, holdsNull) ||
                target.TryGetPropertySetterExplicit(name, out method, value.LimitType, holdsNull))
            {
                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref indexes);
                isByRef = isByRef.AddLast(false);
                var result = BindComInvoke(method, indexes.AddLast(value), binder.CallInfo, isByRef);

                // Make sure to return the value; some languages need it.
                return(new DynamicMetaObject(
                           Expression.Block(result.Expression, Expression.Convert(value.Expression, typeof(object))),
                           result.Restrictions
                           ));
            }

            return(base.BindSetIndex(binder, indexes, value));
        }
Esempio n. 2
0
        public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
        {
            ContractUtils.RequiresNotNull(binder, "binder");

            ComMethodDesc method;

            if (_self.TryGetGetItem(out method))
            {
                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref args);
                return(BindComInvoke(args, method, binder.CallInfo, isByRef));
            }

            return(base.BindInvoke(binder, args));
        }
Esempio n. 3
0
        public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
        {
            ContractUtils.RequiresNotNull(binder, "binder");

            ComMethodDesc getItem;

            if (_self.TryGetGetItem(out getItem))
            {
                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref indexes);
                return(BindComInvoke(indexes, getItem, binder.CallInfo, isByRef));
            }

            return(base.BindGetIndex(binder, indexes));
        }
Esempio n. 4
0
        private DynamicMetaObject BindGetOrInvoke(DynamicMetaObject[] args, CallInfo callInfo)
        {
            //
            // Demand Full Trust to proceed with the binding.
            //

            new PermissionSet(PermissionState.Unrestricted).Demand();

            ComMethodDesc method;
            var           target = _callable.DispatchComObject;
            var           name   = _callable.MemberName;

            if (target.TryGetMemberMethod(name, out method) ||
                target.TryGetMemberMethodExplicit(name, out method))
            {
                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref args);
                return(BindComInvoke(method, args, callInfo, isByRef));
            }
            return(null);
        }
Esempio n. 5
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
        {
            ContractUtils.RequiresNotNull(binder, "binder");

            ComMethodDesc setItem;

            if (_self.TryGetSetItem(out setItem))
            {
                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref indexes);
                isByRef = isByRef.AddLast(false);

                var result = BindComInvoke(indexes.AddLast(value), setItem, binder.CallInfo, isByRef);

                // Make sure to return the value; some languages need it.
                return(new DynamicMetaObject(
                           Expression.Block(result.Expression, Expression.Convert(value.Expression, typeof(object))),
                           result.Restrictions
                           ));
            }

            return(base.BindSetIndex(binder, indexes, value));
        }