public static Com2Properties GetProperties(object obj) { if ((obj == null) || !Marshal.IsComObject(obj)) { return null; } UnsafeNativeMethods.ITypeInfo[] infoArray = FindTypeInfos(obj, false); if ((infoArray == null) || (infoArray.Length == 0)) { return null; } int defaultIndex = -1; int num2 = -1; ArrayList list = new ArrayList(); for (int i = 0; i < infoArray.Length; i++) { UnsafeNativeMethods.ITypeInfo typeInfo = infoArray[i]; if (typeInfo != null) { int[] versions = new int[2]; Guid key = GetGuidForTypeInfo(typeInfo, null, versions); PropertyDescriptor[] props = null; bool flag = ((key != Guid.Empty) && (processedLibraries != null)) && processedLibraries.Contains(key); if (flag) { CachedProperties properties = (CachedProperties) processedLibraries[key]; if ((versions[0] == properties.MajorVersion) && (versions[1] == properties.MinorVersion)) { props = properties.Properties; if ((i == 0) && (properties.DefaultIndex != -1)) { defaultIndex = properties.DefaultIndex; } } else { flag = false; } } if (!flag) { props = InternalGetProperties(obj, typeInfo, -1, ref num2); if ((i == 0) && (num2 != -1)) { defaultIndex = num2; } if (processedLibraries == null) { processedLibraries = new Hashtable(); } if (key != Guid.Empty) { processedLibraries[key] = new CachedProperties(props, (i == 0) ? defaultIndex : -1, versions[0], versions[1]); } } if (props != null) { list.AddRange(props); } } } Com2PropertyDescriptor[] array = new Com2PropertyDescriptor[list.Count]; list.CopyTo(array, 0); return new Com2Properties(obj, array, defaultIndex); }
/// <summary> /// Gets the properties for a given Com2 Object. The returned Com2Properties /// Object contains the properties and relevant data about them. /// </summary> public static Com2Properties GetProperties(object obj) { Debug.WriteLineIf(DbgTypeInfoProcessorSwitch.TraceVerbose, "Com2TypeInfoProcessor.GetProperties"); if (obj == null || !Marshal.IsComObject(obj)) { Debug.WriteLineIf(DbgTypeInfoProcessorSwitch.TraceVerbose, "Com2TypeInfoProcessor.GetProperties returning null: Object is not a com Object"); return(null); } UnsafeNativeMethods.ITypeInfo[] typeInfos = FindTypeInfos(obj, false); // oops, looks like this guy doesn't surface any type info // this is okay, so we just say it has no props if (typeInfos == null || typeInfos.Length == 0) { Debug.WriteLineIf(DbgTypeInfoProcessorSwitch.TraceVerbose, "Com2TypeInfoProcessor.GetProperties :: Didn't get typeinfo"); return(null); } int defaultProp = -1; int temp = -1; ArrayList propList = new ArrayList(); Guid[] typeGuids = new Guid[typeInfos.Length]; for (int i = 0; i < typeInfos.Length; i++) { UnsafeNativeMethods.ITypeInfo ti = typeInfos[i]; if (ti == null) { continue; } int[] versions = new int[2]; Guid typeGuid = GetGuidForTypeInfo(ti, versions); PropertyDescriptor[] props = null; bool dontProcess = typeGuid != Guid.Empty && processedLibraries != null && processedLibraries.Contains(typeGuid); if (dontProcess) { CachedProperties cp = (CachedProperties)processedLibraries[typeGuid]; if (versions[0] == cp.MajorVersion && versions[1] == cp.MinorVersion) { props = cp.Properties; if (i == 0 && cp.DefaultIndex != -1) { defaultProp = cp.DefaultIndex; } } else { dontProcess = false; } } if (!dontProcess) { props = InternalGetProperties(obj, ti, Ole32.DispatchID.MEMBERID_NIL, ref temp); // only save the default property from the first type Info if (i == 0 && temp != -1) { defaultProp = temp; } if (processedLibraries == null) { processedLibraries = new Hashtable(); } if (typeGuid != Guid.Empty) { processedLibraries[typeGuid] = new CachedProperties(props, i == 0 ? defaultProp : -1, versions[0], versions[1]); } } if (props != null) { propList.AddRange(props); } } Debug.WriteLineIf(DbgTypeInfoProcessorSwitch.TraceVerbose, "Com2TypeInfoProcessor.GetProperties : returning " + propList.Count.ToString(CultureInfo.InvariantCulture) + " properties"); // done! Com2PropertyDescriptor[] temp2 = new Com2PropertyDescriptor[propList.Count]; propList.CopyTo(temp2, 0); return(new Com2Properties(obj, temp2, defaultProp)); }