private Guid GetPropertyPageGuid(System.Windows.Forms.NativeMethods.IPerPropertyBrowsing target, int dispid)
        {
            Guid guid;

            if (target.MapPropertyToPage(dispid, out guid) == 0)
            {
                return(guid);
            }
            return(Guid.Empty);
        }
 internal static string GetDisplayString(System.Windows.Forms.NativeMethods.IPerPropertyBrowsing ppb, int dispid, ref bool success)
 {
     string[] pBstr = new string[1];
     if (ppb.GetDisplayString(dispid, pBstr) == 0)
     {
         success = pBstr[0] != null;
         return(pBstr[0]);
     }
     success = false;
     return(null);
 }
 private void OnGetBaseAttributes(Com2PropertyDescriptor sender, GetAttributesEvent attrEvent)
 {
     System.Windows.Forms.NativeMethods.IPerPropertyBrowsing targetObject = sender.TargetObject as System.Windows.Forms.NativeMethods.IPerPropertyBrowsing;
     if (targetObject != null)
     {
         bool flag = !Guid.Empty.Equals(this.GetPropertyPageGuid(targetObject, sender.DISPID));
         if ((sender.CanShow && flag) && typeof(UnsafeNativeMethods.IDispatch).IsAssignableFrom(sender.PropertyType))
         {
             attrEvent.Add(BrowsableAttribute.Yes);
         }
     }
 }
 private void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent)
 {
     if (sender.TargetObject is System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)
     {
         System.Windows.Forms.NativeMethods.IPerPropertyBrowsing targetObject = (System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)sender.TargetObject;
         bool flag = false;
         System.Windows.Forms.NativeMethods.CA_STRUCT pCaStringsOut = new System.Windows.Forms.NativeMethods.CA_STRUCT();
         System.Windows.Forms.NativeMethods.CA_STRUCT pCaCookiesOut = new System.Windows.Forms.NativeMethods.CA_STRUCT();
         int errorCode = 0;
         try
         {
             errorCode = targetObject.GetPredefinedStrings(sender.DISPID, pCaStringsOut, pCaCookiesOut);
         }
         catch (ExternalException exception)
         {
             errorCode = exception.ErrorCode;
         }
         if (gveevent.TypeConverter is Com2IPerPropertyEnumConverter)
         {
             gveevent.TypeConverter = null;
         }
         if (errorCode != 0)
         {
             flag = false;
         }
         else
         {
             flag = true;
         }
         if (flag)
         {
             OleStrCAMarshaler names  = new OleStrCAMarshaler(pCaStringsOut);
             Int32CAMarshaler  values = new Int32CAMarshaler(pCaCookiesOut);
             if ((names.Count > 0) && (values.Count > 0))
             {
                 gveevent.TypeConverter = new Com2IPerPropertyEnumConverter(new Com2IPerPropertyBrowsingEnum(sender, this, names, values, true));
             }
         }
         if (!flag && !sender.ConvertingNativeType)
         {
             Guid propertyPageGuid = this.GetPropertyPageGuid(targetObject, sender.DISPID);
             if (!Guid.Empty.Equals(propertyPageGuid))
             {
                 gveevent.TypeEditor = new Com2PropertyPageUITypeEditor(sender, propertyPageGuid, (UITypeEditor)gveevent.TypeEditor);
             }
         }
     }
 }
 private void ReleaseAxControl()
 {
     this.NoComponentChangeEvents++;
     ContainerControl containingControl = this.ContainingControl;
     if (containingControl != null)
     {
         containingControl.VisibleChanged -= this.onContainerVisibleChanged;
     }
     try
     {
         if (this.instance != null)
         {
             Marshal.FinalReleaseComObject(this.instance);
             this.instance = null;
             this.iOleInPlaceObject = null;
             this.iOleObject = null;
             this.iOleControl = null;
             this.iOleInPlaceActiveObject = null;
             this.iOleInPlaceActiveObjectExternal = null;
             this.iPerPropertyBrowsing = null;
             this.iCategorizeProperties = null;
             this.iPersistStream = null;
             this.iPersistStreamInit = null;
             this.iPersistStorage = null;
         }
         this.axState[checkedIppb] = false;
         this.axState[checkedCP] = false;
         this.axState[disposed] = true;
         this.freezeCount = 0;
         this.axState[sinkAttached] = false;
         this.wndprocAddr = IntPtr.Zero;
         this.SetOcState(0);
     }
     finally
     {
         this.NoComponentChangeEvents--;
     }
 }
 private System.Windows.Forms.NativeMethods.IPerPropertyBrowsing GetPerPropertyBrowsing()
 {
     if (((this.iPerPropertyBrowsing == null) && !this.axState[checkedIppb]) && (this.instance != null))
     {
         this.axState[checkedIppb] = true;
         if (this.instance is System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)
         {
             this.iPerPropertyBrowsing = (System.Windows.Forms.NativeMethods.IPerPropertyBrowsing) this.instance;
         }
     }
     return this.iPerPropertyBrowsing;
 }
 private void EnsureArrays()
 {
     if (!this.arraysFetched)
     {
         this.arraysFetched = true;
         try
         {
             object[] items     = this.nameMarshaller.Items;
             object[] objArray2 = this.valueMarshaller.Items;
             System.Windows.Forms.NativeMethods.IPerPropertyBrowsing targetObject = (System.Windows.Forms.NativeMethods.IPerPropertyBrowsing) this.target.TargetObject;
             int length = 0;
             if (items.Length > 0)
             {
                 object[] sourceArray = new object[objArray2.Length];
                 System.Windows.Forms.NativeMethods.VARIANT pVarOut = new System.Windows.Forms.NativeMethods.VARIANT();
                 System.Type propertyType = this.target.PropertyType;
                 for (int i = items.Length - 1; i >= 0; i--)
                 {
                     int dwCookie = (int)objArray2[i];
                     if ((items[i] != null) && (items[i] is string))
                     {
                         pVarOut.vt = 0;
                         int num4 = targetObject.GetPredefinedValue(this.target.DISPID, dwCookie, pVarOut);
                         if ((num4 == 0) && (pVarOut.vt != 0))
                         {
                             sourceArray[i] = pVarOut.ToObject();
                             if (sourceArray[i].GetType() != propertyType)
                             {
                                 if (propertyType.IsEnum)
                                 {
                                     sourceArray[i] = Enum.ToObject(propertyType, sourceArray[i]);
                                 }
                                 else
                                 {
                                     try
                                     {
                                         sourceArray[i] = Convert.ChangeType(sourceArray[i], propertyType, CultureInfo.InvariantCulture);
                                     }
                                     catch
                                     {
                                     }
                                 }
                             }
                         }
                         pVarOut.Clear();
                         if (num4 == 0)
                         {
                             length++;
                         }
                         else if (length > 0)
                         {
                             Array.Copy(items, i, items, i + 1, length);
                             Array.Copy(sourceArray, i, sourceArray, i + 1, length);
                         }
                     }
                 }
                 string[] destinationArray = new string[length];
                 Array.Copy(items, 0, destinationArray, 0, length);
                 base.PopulateArrays(destinationArray, sourceArray);
             }
         }
         catch (Exception)
         {
             base.PopulateArrays(new string[0], new object[0]);
         }
     }
 }