コード例 #1
0
        internal bool TryGetPropertySetterExplicit(string name, out ComMethodDesc method, Type limitType, bool holdsNull)
        {
            EnsureScanDefinedMethods();

            int hresult = GetIDsOfNames(DispatchObject, name, out int dispId);

            if (hresult == ComHresults.S_OK)
            {
                // we do not know whether we have put or putref here
                // and we will not guess and pretend we found both.
                ComMethodDesc put = new ComMethodDesc(name, dispId, ComTypes.INVOKEKIND.INVOKE_PROPERTYPUT);
                _comTypeDesc.AddPut(name, put);

                ComMethodDesc putref = new ComMethodDesc(name, dispId, ComTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF);
                _comTypeDesc.AddPutRef(name, putref);

                if (ComBinderHelpers.PreferPut(limitType, holdsNull))
                {
                    method = put;
                }
                else
                {
                    method = putref;
                }
                return(true);
            }

            if (hresult == ComHresults.DISP_E_UNKNOWNNAME)
            {
                method = null;
                return(false);
            }

            throw Error.CouldNotGetDispId(name, string.Format(CultureInfo.InvariantCulture, "0x{0:X})", hresult));
        }
コード例 #2
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
        {
            ComMethodDesc setItem;

            if (_self.TryGetSetItem(out setItem))
            {
                List <ParameterExpression> temps     = new List <ParameterExpression>();
                List <Expression>          initTemps = new List <Expression>();

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(setItem, ref indexes, temps, initTemps);
                isByRef = isByRef.AddLast(false);

                // Convert the value to the target type
                DynamicMetaObject updatedValue = new DynamicMetaObject(value.CastOrConvertMethodArgument(
                                                                           value.LimitType,
                                                                           setItem.Name,
                                                                           "SetIndex",
                                                                           temps,
                                                                           initTemps), value.Restrictions);

                var result = BindComInvoke(indexes.AddLast(updatedValue), setItem, binder.CallInfo, isByRef, temps, initTemps);

                // 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));
        }
コード例 #3
0
 protected virtual ComUnwrappedMetaObject UnwrapSelf()
 {
     return(new ComUnwrappedMetaObject(
                ComObject.RcwFromComObject(Expression),
                Restrictions.Merge(ComBinderHelpers.GetTypeRestrictionForDynamicMetaObject(this)),
                ((ComObject)Value).RuntimeCallableWrapper
                ));
 }
コード例 #4
0
        internal bool TryGetPropertySetter(string name, out ComMethodDesc method, Type limitType, bool holdsNull)
        {
            EnsureScanDefinedMethods();

            if (ComBinderHelpers.PreferPut(limitType, holdsNull))
            {
                return(_comTypeDesc.TryGetPut(name, out method) ||
                       _comTypeDesc.TryGetPutRef(name, out method));
            }

            return(_comTypeDesc.TryGetPutRef(name, out method) ||
                   _comTypeDesc.TryGetPut(name, out method));
        }
コード例 #5
0
        public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
        {
            ComMethodDesc method;

            if (_self.TryGetGetItem(out method))
            {
                List <ParameterExpression> temps     = new List <ParameterExpression>();
                List <Expression>          initTemps = new List <Expression>();

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(method, ref args, temps, initTemps);
                return(BindComInvoke(args, method, binder.CallInfo, isByRef, temps, initTemps));
            }

            return(base.BindInvoke(binder, args));
        }
コード例 #6
0
        public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
        {
            ComMethodDesc getItem;

            if (_self.TryGetGetItem(out getItem))
            {
                List <ParameterExpression> temps     = new List <ParameterExpression>();
                List <Expression>          initTemps = new List <Expression>();

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(getItem, ref indexes, temps, initTemps);
                return(BindComInvoke(indexes, getItem, binder.CallInfo, isByRef, temps, initTemps));
            }

            return(base.BindGetIndex(binder, indexes));
        }
コード例 #7
0
        private DynamicMetaObject BindGetOrInvoke(DynamicMetaObject[] args, CallInfo callInfo)
        {
            IDispatchComObject target = _callable.DispatchComObject;
            string             name   = _callable.MemberName;

            if (target.TryGetMemberMethod(name, out ComMethodDesc method) ||
                target.TryGetMemberMethodExplicit(name, out method))
            {
                List <ParameterExpression> temps     = new List <ParameterExpression>();
                List <Expression>          initTemps = new List <Expression>();

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(method, ref args, temps, initTemps);
                return(BindComInvoke(method, args, callInfo, isByRef, temps, initTemps));
            }
            return(null);
        }
コード例 #8
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            Requires.NotNull(binder, nameof(binder));

            ComMethodDesc method = null;

            // See if this is actually a property set
            ComBinder.ComInvokeMemberBinder comInvokeBinder = binder as ComBinder.ComInvokeMemberBinder;
            if ((comInvokeBinder != null) && (comInvokeBinder.IsPropertySet))
            {
                DynamicMetaObject value = args[args.Length - 1];

                bool holdsNull = value.Value == null && value.HasValue;
                if (!_self.TryGetPropertySetter(binder.Name, out method, value.LimitType, holdsNull))
                {
                    _self.TryGetPropertySetterExplicit(binder.Name, out method, value.LimitType, holdsNull);
                }
            }

            // Otherwise, try property get
            if (method == null)
            {
                if (!_self.TryGetMemberMethod(binder.Name, out method))
                {
                    _self.TryGetMemberMethodExplicit(binder.Name, out method);
                }
            }

            if (method != null)
            {
                List <ParameterExpression> temps     = new List <ParameterExpression>();
                List <Expression>          initTemps = new List <Expression>();

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(method, ref args, temps, initTemps);
                return(BindComInvoke(args, method, binder.CallInfo, isByRef, temps, initTemps));
            }

            return(base.BindInvokeMember(binder, args));
        }
コード例 #9
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
        {
            IDispatchComObject target = _callable.DispatchComObject;
            string             name   = _callable.MemberName;

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

            if (target.TryGetPropertySetter(name, out ComMethodDesc method, value.LimitType, holdsNull) ||
                target.TryGetPropertySetterExplicit(name, out method, value.LimitType, holdsNull))
            {
                List <ParameterExpression> temps     = new List <ParameterExpression>();
                List <Expression>          initTemps = new List <Expression>();

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(method, ref indexes, temps, initTemps);
                isByRef = isByRef.AddLast(false);
                // Convert the value to the target type
                DynamicMetaObject updatedValue = new DynamicMetaObject(
                    value.CastOrConvertMethodArgument(
                        value.LimitType,
                        name,
                        "SetIndex",
                        allowCastingToByRefLikeType: false,
                        temps,
                        initTemps),
                    value.Restrictions);

                var result = BindComInvoke(method, indexes.AddLast(updatedValue), binder.CallInfo, isByRef, temps, initTemps);

                // 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));
        }