private static void ProcessVariables(UnsafeNativeMethods.ITypeInfo typeInfo, IDictionary propInfoList, int dispidToGet, int nameDispID, StructCache structCache)
 {
     IntPtr zero = IntPtr.Zero;
     int typeAttr = typeInfo.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);
     try
     {
         if (data != null)
         {
             System.Windows.Forms.NativeMethods.tagVARDESC gvardesc = (System.Windows.Forms.NativeMethods.tagVARDESC) structCache.GetStruct(typeof(System.Windows.Forms.NativeMethods.tagVARDESC));
             for (int i = 0; i < data.cVars; i++)
             {
                 IntPtr pVarDesc = IntPtr.Zero;
                 if (System.Windows.Forms.NativeMethods.Succeeded(typeInfo.GetVarDesc(i, ref pVarDesc)) && (pVarDesc != IntPtr.Zero))
                 {
                     UnsafeNativeMethods.PtrToStructure(pVarDesc, gvardesc);
                     try
                     {
                         if ((gvardesc.varkind != 2) && ((dispidToGet == -1) || (gvardesc.memid == dispidToGet)))
                         {
                             PropInfo info = ProcessDataCore(typeInfo, propInfoList, gvardesc.memid, nameDispID, gvardesc.elemdescVar.tdesc, gvardesc.wVarFlags, structCache);
                             if (info.ReadOnly != 1)
                             {
                                 info.ReadOnly = 2;
                             }
                         }
                     }
                     finally
                     {
                         if (pVarDesc != IntPtr.Zero)
                         {
                             typeInfo.ReleaseVarDesc(pVarDesc);
                         }
                     }
                 }
             }
             structCache.ReleaseStruct(gvardesc);
         }
     }
     finally
     {
         typeInfo.ReleaseTypeAttr(zero);
         structCache.ReleaseStruct(data);
     }
 }
 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;
 }