public static System.Windows.Forms.NativeMethods.VARIANT FromObject(object var)
 {
     System.Windows.Forms.NativeMethods.VARIANT variant = new System.Windows.Forms.NativeMethods.VARIANT();
     if (var == null)
     {
         variant.vt = 0;
         return variant;
     }
     if (!Convert.IsDBNull(var))
     {
         System.Type type = var.GetType();
         if (type == typeof(bool))
         {
             variant.vt = 11;
             return variant;
         }
         if (type == typeof(byte))
         {
             variant.vt = 0x11;
             variant.data1 = (IntPtr) Convert.ToByte(var, CultureInfo.InvariantCulture);
             return variant;
         }
         if (type == typeof(char))
         {
             variant.vt = 0x12;
             variant.data1 = (IntPtr) Convert.ToChar(var, CultureInfo.InvariantCulture);
             return variant;
         }
         if (type == typeof(string))
         {
             variant.vt = 8;
             variant.data1 = SysAllocString(Convert.ToString(var, CultureInfo.InvariantCulture));
             return variant;
         }
         if (type == typeof(short))
         {
             variant.vt = 2;
             variant.data1 = (IntPtr) Convert.ToInt16(var, CultureInfo.InvariantCulture);
             return variant;
         }
         if (type == typeof(int))
         {
             variant.vt = 3;
             variant.data1 = (IntPtr) Convert.ToInt32(var, CultureInfo.InvariantCulture);
             return variant;
         }
         if (type == typeof(long))
         {
             variant.vt = 20;
             variant.SetLong(Convert.ToInt64(var, CultureInfo.InvariantCulture));
             return variant;
         }
         if (type == typeof(decimal))
         {
             variant.vt = 6;
             decimal d = (decimal) var;
             variant.SetLong(decimal.ToInt64(d));
             return variant;
         }
         if (type == typeof(decimal))
         {
             variant.vt = 14;
             decimal num2 = Convert.ToDecimal(var, CultureInfo.InvariantCulture);
             variant.SetLong(decimal.ToInt64(num2));
             return variant;
         }
         if (type == typeof(double))
         {
             variant.vt = 5;
             return variant;
         }
         if ((type == typeof(float)) || (type == typeof(float)))
         {
             variant.vt = 4;
             return variant;
         }
         if (type == typeof(DateTime))
         {
             variant.vt = 7;
             variant.SetLong(Convert.ToDateTime(var, CultureInfo.InvariantCulture).ToFileTime());
             return variant;
         }
         if (type == typeof(sbyte))
         {
             variant.vt = 0x10;
             variant.data1 = (IntPtr) Convert.ToSByte(var, CultureInfo.InvariantCulture);
             return variant;
         }
         if (type == typeof(ushort))
         {
             variant.vt = 0x12;
             variant.data1 = (IntPtr) Convert.ToUInt16(var, CultureInfo.InvariantCulture);
             return variant;
         }
         if (type == typeof(uint))
         {
             variant.vt = 0x13;
             variant.data1 = (IntPtr) Convert.ToUInt32(var, CultureInfo.InvariantCulture);
             return variant;
         }
         if (type == typeof(ulong))
         {
             variant.vt = 0x15;
             variant.SetLong((long) Convert.ToUInt64(var, CultureInfo.InvariantCulture));
             return variant;
         }
         if (((type != typeof(object)) && (type != typeof(System.Windows.Forms.UnsafeNativeMethods.IDispatch))) && !type.IsCOMObject)
         {
             throw new ArgumentException(System.Windows.Forms.SR.GetString("ConnPointUnhandledType", new object[] { type.Name }));
         }
         variant.vt = (type == typeof(System.Windows.Forms.UnsafeNativeMethods.IDispatch)) ? ((short) 9) : ((short) 13);
         variant.data1 = Marshal.GetIUnknownForObject(var);
     }
     return variant;
 }
 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]);
         }
     }
 }
 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 perPropertyBrowsing = this.owner.GetPerPropertyBrowsing();
             int length = 0;
             if (items.Length > 0)
             {
                 object[] values = new object[objArray2.Length];
                 System.Windows.Forms.NativeMethods.VARIANT pVarOut = new System.Windows.Forms.NativeMethods.VARIANT();
                 for (int i = 0; i < items.Length; i++)
                 {
                     int dwCookie = (int) objArray2[i];
                     if ((items[i] != null) && (items[i] is string))
                     {
                         pVarOut.vt = 0;
                         if ((perPropertyBrowsing.GetPredefinedValue(this.target.Dispid, dwCookie, pVarOut) == 0) && (pVarOut.vt != 0))
                         {
                             values[i] = pVarOut.ToObject();
                         }
                         pVarOut.Clear();
                         length++;
                     }
                 }
                 if (length > 0)
                 {
                     string[] destinationArray = new string[length];
                     Array.Copy(items, 0, destinationArray, 0, length);
                     base.PopulateArrays(destinationArray, values);
                 }
             }
         }
         catch (Exception)
         {
         }
     }
 }
 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]);
         }
     }
 }