Esempio n. 1
0
#pragma warning disable 618 // error CS0618: 'VarEnum' is obsolete:
        public Variant(object value)
        {
            this = new Variant();

            if (value == null) this.VariantType = VarEnum.VT_EMPTY;
            else if (value is sbyte) this.AsI1 = (sbyte)value;
            else if (value is byte) this.AsUi1 = (byte)value;
            else if (value is short) this.AsI2 = (short)value;
            else if (value is ushort) this.AsUi2 = (ushort)value;
            else if (value is char)
            {
                char unboxedChar = (char)value;
                this.AsUi2 = (ushort)unboxedChar;
            }
            else if (value is int) this.AsI4 = (int)value;
            else if (value is uint) this.AsUi4 = (uint)value;
            else if (value is long) this.AsI8 = (long)value;
            else if (value is ulong) this.AsUi8 = (ulong)value;
            else if (value is bool) this.AsBool = (bool)value;
            else if (value is decimal) this.AsDecimal = (decimal)value;
            else if (value is double) this.AsR8 = (double)value;
            else if (value is float) this.AsR4 = (float)value;
            else if (value is string) this.AsBstr = (string)value;
            else if (value is Array || value is SafeHandle || value is CriticalHandle || value is VariantWrapper)
            {
                throw new ArgumentException(SR.Format(SR.Arg_VariantTypeNotSupported, value.GetTypeHandle().GetDisplayName()));
            }
            else
            {
                this.AsUnknown = value;
            }
        }
Esempio n. 2
0
        public static object GetObjectForNativeVariant(IntPtr pSrcNativeVariant)
        {
            Variant vt = (Variant)Marshal.PtrToStructure(pSrcNativeVariant, typeof(Variant));

            return(vt.GetValue());
        }
Esempio n. 3
0
#pragma warning disable 618 // error CS0618: 'VarEnum' is obsolete:
        public Variant(object value)
        {
            this = new Variant();

            if (value == null)
            {
                this.VariantType = VarEnum.VT_EMPTY;
            }
            else if (value is sbyte)
            {
                this.AsI1 = (sbyte)value;
            }
            else if (value is byte)
            {
                this.AsUi1 = (byte)value;
            }
            else if (value is short)
            {
                this.AsI2 = (short)value;
            }
            else if (value is ushort)
            {
                this.AsUi2 = (ushort)value;
            }
            else if (value is char)
            {
                char unboxedChar = (char)value;
                this.AsUi2 = (ushort)unboxedChar;
            }
            else if (value is int)
            {
                this.AsI4 = (int)value;
            }
            else if (value is uint)
            {
                this.AsUi4 = (uint)value;
            }
            else if (value is long)
            {
                this.AsI8 = (long)value;
            }
            else if (value is ulong)
            {
                this.AsUi8 = (ulong)value;
            }
            else if (value is bool)
            {
                this.AsBool = (bool)value;
            }
            else if (value is decimal)
            {
                this.AsDecimal = (decimal)value;
            }
            else if (value is double)
            {
                this.AsR8 = (double)value;
            }
            else if (value is float)
            {
                this.AsR4 = (float)value;
            }
            else if (value is string)
            {
                this.AsBstr = (string)value;
            }
            else if (value is Array || value is SafeHandle || value is CriticalHandle || value is VariantWrapper)
            {
                throw new ArgumentException(SR.Format(SR.Arg_VariantTypeNotSupported, value.GetTypeHandle().GetDisplayName()));
            }
            else
            {
                this.AsUnknown = value;
            }
        }
 public void SetAsByrefVariant(ref Variant value)
 {
     SetAsByref(ref value, VarEnum.VT_VARIANT);
 }