예제 #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
 protected virtual ComUnwrappedMetaObject UnwrapSelf() {
     return new ComUnwrappedMetaObject(
         ComObject.RcwFromComObject(Expression),
         Restrictions.Merge(ComBinderHelpers.GetTypeRestrictionForDynamicMetaObject(this)),
         ((ComObject)Value).RuntimeCallableWrapper
     );
 }
예제 #3
0
        public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
        {
            ContractUtils.RequiresNotNull(binder, nameof(binder));

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

            return(base.BindInvoke(binder, args));
        }
예제 #4
0
        public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
        {
            ContractUtils.RequiresNotNull(binder, nameof(binder));

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

            return(base.BindGetIndex(binder, indexes));
        }
예제 #5
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));
        }
예제 #6
0
        private DynamicMetaObject BindGetOrInvoke(DynamicMetaObject[] args, CallInfo callInfo)
        {
            var target = _callable.DispatchComObject;
            var name   = _callable.MemberName;

            if (target.TryGetMemberMethod(name, out ComMethodDesc method) ||
                target.TryGetMemberMethodExplicit(name, out method))
            {
                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref args);
                return(BindComInvoke(method, args, callInfo, isByRef));
            }
            return(null);
        }
예제 #7
0
        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
        {
            ContractUtils.RequiresNotNull(binder, "binder");

            ComMethodDesc method;

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

            return(base.BindInvokeMember(binder, args));
        }
예제 #8
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
        {
            ContractUtils.RequiresNotNull(binder, nameof(binder));

            if (_self.TryGetSetItem(out ComMethodDesc 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));
        }
예제 #9
0
        internal DynamicMetaObject Invoke()
        {
            _keywordArgNames   = _callInfo.ArgumentNames.ToArray();
            _totalExplicitArgs = _args.Length;

            Type[] marshalArgTypes = new Type[_args.Length];

            // We already tested the instance, so no need to test it again
            for (int i = 0; i < _args.Length; i++)
            {
                DynamicMetaObject curMo = _args[i];
                _restrictions      = _restrictions.Merge(ComBinderHelpers.GetTypeRestrictionForDynamicMetaObject(curMo));
                marshalArgTypes[i] = MarshalType(curMo, _isByRef[i]);
            }

            _varEnumSelector = new VarEnumSelector(marshalArgTypes);

            return(new DynamicMetaObject(
                       CreateScope(MakeIDispatchInvokeTarget()),
                       BindingRestrictions.Combine(_args).Merge(_restrictions)
                       ));
        }
예제 #10
0
        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
        {
            var target = _callable.DispatchComObject;
            var 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))
            {
                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));
        }