internal override IList <string> GetMemberNames(bool dataOnly) { EnsureScanDefinedMethods(); EnsureScanDefinedEvents(); return(ComTypeDesc.GetMemberNames(dataOnly)); }
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 = EmptyEvents; return typeDesc; }
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 = EmptyEvents; return(typeDesc); }
internal static ComTypeDesc CreateEmptyTypeDesc() { ComTypeDesc typeDesc = new ComTypeDesc(null, null) { Funcs = new Hashtable(), Puts = new Hashtable(), PutRefs = new Hashtable(), Events = EmptyEvents }; return(typeDesc); }
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) ) ) )); }
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)); }
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, Utils.EmptyArray <object>(), 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()); }
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, null); return(typeDesc); default: throw new InvalidOperationException("Attempting to wrap an unsupported enum type."); } }
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."); } }
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."); } }
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 (s_cacheComTypeDesc) { if (s_cacheComTypeDesc.TryGetValue(typeAttr.guid, out _comTypeDesc) == true && _comTypeDesc.Funcs != null) { return; } } } if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_INTERFACE) { // We have typeinfo for custom interface. Get typeinfo for Dispatch interface. typeInfo = ComTypeInfo.GetDispatchTypeInfoFromCustomInterfaceTypeInfo(typeInfo); typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo); } if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_COCLASS) { // We have typeinfo for the COClass. Find the default interface and get typeinfo for default interface. typeInfo = ComTypeInfo.GetDispatchTypeInfoFromCoClassTypeInfo(typeInfo); typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo); } 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) { // If there is a getter for this put, use that ReturnType as the // PropertyType. if (funcs.ContainsKey(name)) { method.InputType = ((ComMethodDesc)funcs[name]).ReturnType; } 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) { // If there is a getter for this put, use that ReturnType as the // PropertyType. if (funcs.ContainsKey(name)) { method.InputType = ((ComMethodDesc)funcs[name]).ReturnType; } 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; } // If there is a setter for this put, update the InputType from our // ReturnType. if (puts.ContainsKey(name)) { ((ComMethodDesc)puts[name]).InputType = method.ReturnType; } if (putrefs.ContainsKey(name)) { ((ComMethodDesc)putrefs[name]).InputType = method.ReturnType; } 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 (s_cacheComTypeDesc) { ComTypeDesc cachedTypeDesc; if (s_cacheComTypeDesc.TryGetValue(typeAttr.guid, out cachedTypeDesc)) { _comTypeDesc = cachedTypeDesc; } else { _comTypeDesc = typeDesc; s_cacheComTypeDesc.Add(typeAttr.guid, _comTypeDesc); } _comTypeDesc.Funcs = funcs; _comTypeDesc.Puts = puts; _comTypeDesc.PutRefs = putrefs; _comTypeDesc.EnsureGetItem(getItem); _comTypeDesc.EnsureSetItem(setItem); } }
private void EnsureScanDefinedEvents() { // _comTypeDesc.Events is null if we have not yet attempted // to scan the object for events. if (_comTypeDesc != null && _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 (s_cacheComTypeDesc) { if (s_cacheComTypeDesc.TryGetValue(typeAttr.guid, out _comTypeDesc) == true && _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 (s_cacheComTypeDesc) { ComTypeDesc cachedTypeDesc; if (s_cacheComTypeDesc.TryGetValue(typeAttr.guid, out cachedTypeDesc)) { _comTypeDesc = cachedTypeDesc; } else { _comTypeDesc = typeDesc; s_cacheComTypeDesc.Add(typeAttr.guid, _comTypeDesc); } _comTypeDesc.Events = events; } }