Inheritance: Microsoft.Scripting.ComInterop.ComTypeLibMemberDesc
Exemplo n.º 1
0
        internal override IList <string> GetMemberNames(bool dataOnly)
        {
            EnsureScanDefinedMethods();
            EnsureScanDefinedEvents();

            return(ComTypeDesc.GetMemberNames(dataOnly));
        }
Exemplo n.º 2
0
        internal static ComTypeDesc CreateEmptyTypeDesc() {
            ComTypeDesc typeDesc = new ComTypeDesc(null, ComType.Interface, null);
            typeDesc._funcs = new Dictionary<string, ComMethodDesc>();
            typeDesc._events = _EmptyEventsDict;

            return typeDesc;
        }
Exemplo n.º 3
0
        internal static ComTypeDesc CreateEmptyTypeDesc() {
            ComTypeDesc typeDesc = new ComTypeDesc(null, ComType.Interface, null);
            typeDesc._funcs = new Hashtable();
            typeDesc._puts = new Hashtable();
            typeDesc._putRefs = new Hashtable();
            typeDesc._events = _EmptyEventsDict;

            return typeDesc;
        }
Exemplo n.º 4
0
        internal static ComTypeDesc CreateEmptyTypeDesc()
        {
            ComTypeDesc typeDesc = new ComTypeDesc(null, ComType.Interface, null);

            typeDesc._funcs  = new Dictionary <string, ComMethodDesc>();
            typeDesc._events = _EmptyEventsDict;

            return(typeDesc);
        }
Exemplo n.º 5
0
        internal static ComTypeDesc CreateEmptyTypeDesc()
        {
            ComTypeDesc typeDesc = new ComTypeDesc(null, ComType.Interface, null);

            typeDesc._funcs   = new Hashtable();
            typeDesc._puts    = new Hashtable();
            typeDesc._putRefs = new Hashtable();
            typeDesc._events  = _EmptyEventsDict;

            return(typeDesc);
        }
Exemplo n.º 6
0
 internal static ComTypeDesc FromITypeInfo(ComTypes.ITypeInfo typeInfo, ComTypes.TYPEATTR typeAttr) {
     if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_COCLASS) {
         return new ComTypeClassDesc(typeInfo, null);
     } else if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_ENUM) {
         return new ComTypeEnumDesc(typeInfo, null);
     } else if ((typeAttr.typekind == ComTypes.TYPEKIND.TKIND_DISPATCH) ||
           (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_INTERFACE)) {
         ComTypeDesc typeDesc = new ComTypeDesc(typeInfo, ComType.Interface, null);
         return typeDesc;
     } else {
         throw new InvalidOperationException("Attempting to wrap an unsupported enum type.");
     }
 }
Exemplo n.º 7
0
 internal static BindingRestrictions IDispatchRestriction(Expression expr, ComTypeDesc typeDesc)
 {
     return(BindingRestrictions.GetTypeRestriction(
                expr, typeof(IDispatchComObject)
                ).Merge(
                BindingRestrictions.GetExpressionRestriction(
                    Expression.Equal(
                        Expression.Property(
                            Helpers.Convert(expr, typeof(IDispatchComObject)),
                            typeof(IDispatchComObject).GetProperty("ComTypeDesc")
                            ),
                        Expression.Constant(typeDesc)
                        )
                    )
                ));
 }
Exemplo n.º 8
0
        public override string ToString()
        {
            ComTypeDesc ctd      = _comTypeDesc;
            string      typeName = null;

            if (ctd != null)
            {
                typeName = ctd.TypeName;
            }

            if (String.IsNullOrEmpty(typeName))
            {
                typeName = "IDispatch";
            }

            return(String.Format(CultureInfo.CurrentCulture, "{0} ({1})", RuntimeCallableWrapper.ToString(), typeName));
        }
Exemplo n.º 9
0
        internal static ComTypeDesc FromITypeInfo(ITypeInfo typeInfo, TYPEATTR typeAttr)
        {
            switch (typeAttr.typekind)
            {
            case TYPEKIND.TKIND_COCLASS:
                return(new ComTypeClassDesc(typeInfo, null));

            case TYPEKIND.TKIND_ENUM:
                return(new ComTypeEnumDesc(typeInfo, null));

            case TYPEKIND.TKIND_DISPATCH:
            case TYPEKIND.TKIND_INTERFACE:
                ComTypeDesc typeDesc = new ComTypeDesc(typeInfo, ComType.Interface, null);
                return(typeDesc);

            default:
                throw new InvalidOperationException("Attempting to wrap an unsupported enum type.");
            }
        }
Exemplo n.º 10
0
        internal override IList <KeyValuePair <string, object> > GetMembers(IEnumerable <string> names)
        {
            if (names == null)
            {
                names = GetMemberNames(true);
            }

            Type comType = RuntimeCallableWrapper.GetType();

            var members = new List <KeyValuePair <string, object> >();

            foreach (string name in names)
            {
                if (name == null)
                {
                    continue;
                }

                ComMethodDesc method;
                if (ComTypeDesc.TryGetFunc(name, out method) && method.IsDataMember)
                {
                    try {
                        object value = comType.InvokeMember(
                            method.Name,
                            BindingFlags.GetProperty,
                            null,
                            RuntimeCallableWrapper,
                            new object[0],
                            CultureInfo.InvariantCulture
                            );
                        members.Add(new KeyValuePair <string, object>(method.Name, value));

                        //evaluation failed for some reason. pass exception out
                    } catch (Exception ex) {
                        members.Add(new KeyValuePair <string, object>(method.Name, ex));
                    }
                }
            }

            return(members.ToArray());
        }
Exemplo n.º 11
0
 internal static ComTypeDesc FromITypeInfo(ComTypes.ITypeInfo typeInfo, ComTypes.TYPEATTR typeAttr)
 {
     if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_COCLASS)
     {
         return(new ComTypeClassDesc(typeInfo, null));
     }
     else if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_ENUM)
     {
         return(new ComTypeEnumDesc(typeInfo, null));
     }
     else if ((typeAttr.typekind == ComTypes.TYPEKIND.TKIND_DISPATCH) ||
              (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_INTERFACE))
     {
         ComTypeDesc typeDesc = new ComTypeDesc(typeInfo, ComType.Interface, null);
         return(typeDesc);
     }
     else
     {
         throw new InvalidOperationException("Attempting to wrap an unsupported enum type.");
     }
 }
Exemplo n.º 12
0
        private void EnsureScanDefinedMethods()
        {
            if (_comTypeDesc != null && _comTypeDesc.Funcs != null)
            {
                return;
            }

            ComTypes.ITypeInfo typeInfo = ComRuntimeHelpers.GetITypeInfoFromIDispatch(_dispatchObject, true);
            if (typeInfo == null)
            {
                _comTypeDesc = ComTypeDesc.CreateEmptyTypeDesc();
                return;
            }

            ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);

            if (_comTypeDesc == null)
            {
                lock (_CacheComTypeDesc) {
                    if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out _comTypeDesc) &&
                        _comTypeDesc.Funcs != null)
                    {
                        return;
                    }
                }
            }

            ComTypeDesc typeDesc = ComTypeDesc.FromITypeInfo(typeInfo, typeAttr);

            ComMethodDesc getItem = null;
            ComMethodDesc setItem = null;
            Hashtable     funcs   = new Hashtable(typeAttr.cFuncs);
            Hashtable     puts    = new Hashtable();
            Hashtable     putrefs = new Hashtable();

            for (int definedFuncIndex = 0; definedFuncIndex < typeAttr.cFuncs; definedFuncIndex++)
            {
                IntPtr funcDescHandleToRelease = IntPtr.Zero;

                try {
                    ComTypes.FUNCDESC funcDesc;
                    GetFuncDescForDescIndex(typeInfo, definedFuncIndex, out funcDesc, out funcDescHandleToRelease);

                    if ((funcDesc.wFuncFlags & (int)ComTypes.FUNCFLAGS.FUNCFLAG_FRESTRICTED) != 0)
                    {
                        // This function is not meant for the script user to use.
                        continue;
                    }

                    ComMethodDesc method = new ComMethodDesc(typeInfo, funcDesc);
                    string        name   = method.Name.ToUpper(System.Globalization.CultureInfo.InvariantCulture);

                    if ((funcDesc.invkind & ComTypes.INVOKEKIND.INVOKE_PROPERTYPUT) != 0)
                    {
                        puts.Add(name, method);

                        // for the special dispId == 0, we need to store
                        // the method descriptor for the Do(SetItem) binder.
                        if (method.DispId == ComDispIds.DISPID_VALUE && setItem == null)
                        {
                            setItem = method;
                        }
                        continue;
                    }
                    if ((funcDesc.invkind & ComTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF) != 0)
                    {
                        putrefs.Add(name, method);
                        // for the special dispId == 0, we need to store
                        // the method descriptor for the Do(SetItem) binder.
                        if (method.DispId == ComDispIds.DISPID_VALUE && setItem == null)
                        {
                            setItem = method;
                        }
                        continue;
                    }

                    if (funcDesc.memid == ComDispIds.DISPID_NEWENUM)
                    {
                        funcs.Add("GETENUMERATOR", method);
                        continue;
                    }

                    funcs.Add(name, method);

                    // for the special dispId == 0, we need to store the method descriptor
                    // for the Do(GetItem) binder.
                    if (funcDesc.memid == ComDispIds.DISPID_VALUE)
                    {
                        getItem = method;
                    }
                } finally {
                    if (funcDescHandleToRelease != IntPtr.Zero)
                    {
                        typeInfo.ReleaseFuncDesc(funcDescHandleToRelease);
                    }
                }
            }

            lock (_CacheComTypeDesc) {
                ComTypeDesc cachedTypeDesc;
                if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out cachedTypeDesc))
                {
                    _comTypeDesc = cachedTypeDesc;
                }
                else
                {
                    _comTypeDesc = typeDesc;
                    _CacheComTypeDesc.Add(typeAttr.guid, _comTypeDesc);
                }
                _comTypeDesc.Funcs   = funcs;
                _comTypeDesc.Puts    = puts;
                _comTypeDesc.PutRefs = putrefs;
                _comTypeDesc.EnsureGetItem(getItem);
                _comTypeDesc.EnsureSetItem(setItem);
            }
        }
Exemplo n.º 13
0
        private void EnsureScanDefinedEvents()
        {
            // _comTypeDesc.Events is null if we have not yet attempted
            // to scan the object for events.
            if (_comTypeDesc?.Events != null)
            {
                return;
            }

            // check type info in the type descriptions cache
            ComTypes.ITypeInfo typeInfo = ComRuntimeHelpers.GetITypeInfoFromIDispatch(_dispatchObject, true);
            if (typeInfo == null)
            {
                _comTypeDesc = ComTypeDesc.CreateEmptyTypeDesc();
                return;
            }

            ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo);

            if (_comTypeDesc == null)
            {
                lock (_CacheComTypeDesc) {
                    if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out _comTypeDesc) &&
                        _comTypeDesc.Events != null)
                    {
                        return;
                    }
                }
            }

            ComTypeDesc typeDesc = ComTypeDesc.FromITypeInfo(typeInfo, typeAttr);

            ComTypes.ITypeInfo classTypeInfo         = null;
            Dictionary <string, ComEventDesc> events = null;

            var cpc = RuntimeCallableWrapper as ComTypes.IConnectionPointContainer;

            if (cpc == null)
            {
                // No ICPC - this object does not support events
                events = ComTypeDesc.EmptyEvents;
            }
            else if ((classTypeInfo = GetCoClassTypeInfo(this.RuntimeCallableWrapper, typeInfo)) == null)
            {
                // no class info found - this object may support events
                // but we could not discover those
                events = ComTypeDesc.EmptyEvents;
            }
            else
            {
                events = new Dictionary <string, ComEventDesc>();

                ComTypes.TYPEATTR classTypeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(classTypeInfo);
                for (int i = 0; i < classTypeAttr.cImplTypes; i++)
                {
                    int hRefType;
                    classTypeInfo.GetRefTypeOfImplType(i, out hRefType);

                    ComTypes.ITypeInfo interfaceTypeInfo;
                    classTypeInfo.GetRefTypeInfo(hRefType, out interfaceTypeInfo);

                    ComTypes.IMPLTYPEFLAGS flags;
                    classTypeInfo.GetImplTypeFlags(i, out flags);
                    if ((flags & ComTypes.IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE) != 0)
                    {
                        ScanSourceInterface(interfaceTypeInfo, ref events);
                    }
                }

                if (events.Count == 0)
                {
                    events = ComTypeDesc.EmptyEvents;
                }
            }

            lock (_CacheComTypeDesc) {
                ComTypeDesc cachedTypeDesc;
                if (_CacheComTypeDesc.TryGetValue(typeAttr.guid, out cachedTypeDesc))
                {
                    _comTypeDesc = cachedTypeDesc;
                }
                else
                {
                    _comTypeDesc = typeDesc;
                    _CacheComTypeDesc.Add(typeAttr.guid, _comTypeDesc);
                }
                _comTypeDesc.Events = events;
            }
        }