private static System.Type ProcessTypeInfoEnum(UnsafeNativeMethods.ITypeInfo enumTypeInfo, StructCache structCache)
 {
     if (enumTypeInfo != null)
     {
         try
         {
             IntPtr zero = IntPtr.Zero;
             int typeAttr = enumTypeInfo.GetTypeAttr(ref zero);
             if (!System.Windows.Forms.NativeMethods.Succeeded(typeAttr) || (zero == IntPtr.Zero))
             {
                 throw new ExternalException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetTypeAttrFailed", new object[] { typeAttr }), typeAttr);
             }
             System.Windows.Forms.NativeMethods.tagTYPEATTR data = (System.Windows.Forms.NativeMethods.tagTYPEATTR) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagTYPEATTR));
             UnsafeNativeMethods.PtrToStructure(zero, data);
             if (zero == IntPtr.Zero)
             {
                 return null;
             }
             try
             {
                 int cVars = data.cVars;
                 ArrayList list = new ArrayList();
                 ArrayList list2 = new ArrayList();
                 System.Windows.Forms.NativeMethods.tagVARDESC gvardesc = (System.Windows.Forms.NativeMethods.tagVARDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagVARDESC));
                 object objectForNativeVariant = null;
                 string pBstrName = null;
                 string pBstrDocString = null;
                 enumTypeInfo.GetDocumentation(-1, ref pBstrName, ref pBstrDocString, null, null);
                 for (int i = 0; i < cVars; i++)
                 {
                     IntPtr pVarDesc = IntPtr.Zero;
                     if (System.Windows.Forms.NativeMethods.Succeeded(enumTypeInfo.GetVarDesc(i, ref pVarDesc)) && (pVarDesc != IntPtr.Zero))
                     {
                         try
                         {
                             UnsafeNativeMethods.PtrToStructure(pVarDesc, gvardesc);
                             if (((gvardesc != null) && (gvardesc.varkind == 2)) && (gvardesc.unionMember != IntPtr.Zero))
                             {
                                 str2 = (string) (pBstrDocString = null);
                                 objectForNativeVariant = null;
                                 if (System.Windows.Forms.NativeMethods.Succeeded(enumTypeInfo.GetDocumentation(gvardesc.memid, null, ref pBstrDocString, null, null)))
                                 {
                                     string str4;
                                     try
                                     {
                                         objectForNativeVariant = Marshal.GetObjectForNativeVariant(gvardesc.unionMember);
                                     }
                                     catch (Exception)
                                     {
                                     }
                                     list2.Add(objectForNativeVariant);
                                     if (pBstrDocString != null)
                                     {
                                         str4 = pBstrDocString;
                                     }
                                     else
                                     {
                                         str4 = str2;
                                     }
                                     list.Add(str4);
                                 }
                             }
                         }
                         finally
                         {
                             if (pVarDesc != IntPtr.Zero)
                             {
                                 enumTypeInfo.ReleaseVarDesc(pVarDesc);
                             }
                         }
                     }
                 }
                 structCache.ReleaseStruct(gvardesc);
                 if (list.Count > 0)
                 {
                     IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(enumTypeInfo);
                     try
                     {
                         pBstrName = iUnknownForObject.ToString() + "_" + pBstrName;
                         if (builtEnums == null)
                         {
                             builtEnums = new Hashtable();
                         }
                         else if (builtEnums.ContainsKey(pBstrName))
                         {
                             return (System.Type) builtEnums[pBstrName];
                         }
                         System.Type underlyingType = typeof(int);
                         if ((list2.Count > 0) && (list2[0] != null))
                         {
                             underlyingType = list2[0].GetType();
                         }
                         EnumBuilder builder = ModuleBuilder.DefineEnum(pBstrName, TypeAttributes.Public, underlyingType);
                         for (int j = 0; j < list.Count; j++)
                         {
                             builder.DefineLiteral((string) list[j], list2[j]);
                         }
                         System.Type type2 = builder.CreateType();
                         builtEnums[pBstrName] = type2;
                         return type2;
                     }
                     finally
                     {
                         if (iUnknownForObject != IntPtr.Zero)
                         {
                             Marshal.Release(iUnknownForObject);
                         }
                     }
                 }
             }
             finally
             {
                 enumTypeInfo.ReleaseTypeAttr(zero);
                 structCache.ReleaseStruct(data);
             }
         }
         catch
         {
         }
     }
     return null;
 }
 private static PropInfo ProcessDataCore(UnsafeNativeMethods.ITypeInfo typeInfo, IDictionary propInfoList, int dispid, int nameDispID, System.Windows.Forms.NativeMethods.tagTYPEDESC typeDesc, int flags, StructCache structCache)
 {
     string pBstrName = null;
     string pBstrDocString = null;
     int hr = typeInfo.GetDocumentation(dispid, ref pBstrName, ref pBstrDocString, null, null);
     ComNativeDescriptor instance = ComNativeDescriptor.Instance;
     if (!System.Windows.Forms.NativeMethods.Succeeded(hr))
     {
         throw new COMException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetDocumentationFailed", new object[] { dispid, hr, instance.GetClassName(typeInfo) }), hr);
     }
     if (pBstrName == null)
     {
         return null;
     }
     PropInfo info = (PropInfo) propInfoList[pBstrName];
     if (info == null)
     {
         info = new PropInfo {
             Index = propInfoList.Count
         };
         propInfoList[pBstrName] = info;
         info.Name = pBstrName;
         info.DispId = dispid;
         info.Attributes.Add(new DispIdAttribute(info.DispId));
     }
     if (pBstrDocString != null)
     {
         info.Attributes.Add(new DescriptionAttribute(pBstrDocString));
     }
     if (info.ValueType == null)
     {
         object[] typeData = new object[1];
         try
         {
             info.ValueType = GetValueTypeFromTypeDesc(typeDesc, typeInfo, typeData, structCache);
         }
         catch (Exception)
         {
         }
         if (info.ValueType == null)
         {
             info.NonBrowsable = true;
         }
         if (info.NonBrowsable)
         {
             flags |= 0x400;
         }
         if (typeData[0] != null)
         {
             info.TypeData = typeData[0];
         }
     }
     if ((flags & 1) != 0)
     {
         info.ReadOnly = 1;
     }
     if ((((flags & 0x40) != 0) || ((flags & 0x400) != 0)) || ((info.Name[0] == '_') || (dispid == -515)))
     {
         info.Attributes.Add(new BrowsableAttribute(false));
         info.NonBrowsable = true;
     }
     if ((flags & 0x200) != 0)
     {
         info.IsDefault = true;
     }
     if (((flags & 4) != 0) && ((flags & 0x10) != 0))
     {
         info.Attributes.Add(new BindableAttribute(true));
     }
     if (dispid == nameDispID)
     {
         info.Attributes.Add(new ParenthesizePropertyNameAttribute(true));
         info.Attributes.Add(new MergablePropertyAttribute(false));
     }
     return info;
 }