Exemplo n.º 1
0
 static Variant()
 {
     ClassTypes = new Type[] {
         typeof(System.Empty), typeof(void), typeof(bool), typeof(char), typeof(sbyte), typeof(byte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(void),
         typeof(DateTime), typeof(TimeSpan), typeof(object), typeof(decimal), typeof(object), typeof(System.Reflection.Missing), typeof(System.DBNull)
     };
     Empty   = new System.Variant();
     Missing = new System.Variant(0x16, Type.Missing, 0, 0);
     DBNull  = new System.Variant(0x17, System.DBNull.Value, 0, 0);
 }
        public override object ChangeType(object value, Type type, CultureInfo cultureInfo)
        {
            object obj3;

            System.Variant source = new System.Variant(value);
            if (cultureInfo == null)
            {
                cultureInfo = CultureInfo.CurrentCulture;
            }
            if (type.IsByRef)
            {
                type = type.GetElementType();
            }
            if (!type.IsPrimitive && type.IsInstanceOfType(value))
            {
                return(value);
            }
            Type type2 = value.GetType();

            if (type.IsEnum && type2.IsPrimitive)
            {
                return(Enum.Parse(type, value.ToString()));
            }
            if (type2 == typeof(DBNull))
            {
                if (type == typeof(DBNull))
                {
                    return(value);
                }
                if ((type.IsClass && (type != typeof(object))) || type.IsInterface)
                {
                    return(null);
                }
            }
            try
            {
                obj3 = OAVariantLib.ChangeType(source, type, 0x10, cultureInfo).ToObject();
            }
            catch (NotSupportedException)
            {
                throw new COMException(Environment.GetResourceString("Interop.COM_TypeMismatch"), -2147352571);
            }
            return(obj3);
        }
 public override object ChangeType(object value, Type type, CultureInfo cultureInfo)
 {
     object obj3;
     System.Variant source = new System.Variant(value);
     if (cultureInfo == null)
     {
         cultureInfo = CultureInfo.CurrentCulture;
     }
     if (type.IsByRef)
     {
         type = type.GetElementType();
     }
     if (!type.IsPrimitive && type.IsInstanceOfType(value))
     {
         return value;
     }
     Type type2 = value.GetType();
     if (type.IsEnum && type2.IsPrimitive)
     {
         return Enum.Parse(type, value.ToString());
     }
     if (type2 == typeof(DBNull))
     {
         if (type == typeof(DBNull))
         {
             return value;
         }
         if ((type.IsClass && (type != typeof(object))) || type.IsInterface)
         {
             return null;
         }
     }
     try
     {
         obj3 = OAVariantLib.ChangeType(source, type, 0x10, cultureInfo).ToObject();
     }
     catch (NotSupportedException)
     {
         throw new COMException(Environment.GetResourceString("Interop.COM_TypeMismatch"), -2147352571);
     }
     return obj3;
 }
 static Variant()
 {
     ClassTypes = new Type[] { 
         typeof(System.Empty), typeof(void), typeof(bool), typeof(char), typeof(sbyte), typeof(byte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(void), 
         typeof(DateTime), typeof(TimeSpan), typeof(object), typeof(decimal), typeof(object), typeof(System.Reflection.Missing), typeof(System.DBNull)
      };
     Empty = new System.Variant();
     Missing = new System.Variant(0x16, Type.Missing, 0, 0);
     DBNull = new System.Variant(0x17, System.DBNull.Value, 0, 0);
 }
        internal static void MarshalHelperCastVariant(object pValue, int vt, ref System.Variant v)
        {
            IConvertible convertible = pValue as IConvertible;
            if (convertible != null)
            {
                IFormatProvider invariantCulture = CultureInfo.InvariantCulture;
                switch (vt)
                {
                    case 0:
                        v = Empty;
                        return;

                    case 1:
                        v = DBNull;
                        return;

                    case 2:
                        v = new System.Variant(convertible.ToInt16(invariantCulture));
                        return;

                    case 3:
                        v = new System.Variant(convertible.ToInt32(invariantCulture));
                        return;

                    case 4:
                        v = new System.Variant(convertible.ToSingle(invariantCulture));
                        return;

                    case 5:
                        v = new System.Variant(convertible.ToDouble(invariantCulture));
                        return;

                    case 6:
                        v = new System.Variant(new CurrencyWrapper(convertible.ToDecimal(invariantCulture)));
                        return;

                    case 7:
                        v = new System.Variant(convertible.ToDateTime(invariantCulture));
                        return;

                    case 8:
                        v = new System.Variant(convertible.ToString(invariantCulture));
                        return;

                    case 9:
                        v = new System.Variant(new DispatchWrapper(convertible));
                        return;

                    case 10:
                        v = new System.Variant(new ErrorWrapper(convertible.ToInt32(invariantCulture)));
                        return;

                    case 11:
                        v = new System.Variant(convertible.ToBoolean(invariantCulture));
                        return;

                    case 12:
                        v = new System.Variant(convertible);
                        return;

                    case 13:
                        v = new System.Variant(new UnknownWrapper(convertible));
                        return;

                    case 14:
                        v = new System.Variant(convertible.ToDecimal(invariantCulture));
                        return;

                    case 0x10:
                        v = new System.Variant(convertible.ToSByte(invariantCulture));
                        return;

                    case 0x11:
                        v = new System.Variant(convertible.ToByte(invariantCulture));
                        return;

                    case 0x12:
                        v = new System.Variant(convertible.ToUInt16(invariantCulture));
                        return;

                    case 0x13:
                        v = new System.Variant(convertible.ToUInt32(invariantCulture));
                        return;

                    case 20:
                        v = new System.Variant(convertible.ToInt64(invariantCulture));
                        return;

                    case 0x15:
                        v = new System.Variant(convertible.ToUInt64(invariantCulture));
                        return;

                    case 0x16:
                        v = new System.Variant(convertible.ToInt32(invariantCulture));
                        return;

                    case 0x17:
                        v = new System.Variant(convertible.ToUInt32(invariantCulture));
                        return;
                }
                throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
            }
            switch (vt)
            {
                case 8:
                    if (pValue != null)
                    {
                        throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                    }
                    v = new System.Variant(null);
                    v.m_flags = 14;
                    return;

                case 9:
                    v = new System.Variant(new DispatchWrapper(pValue));
                    return;

                case 12:
                    v = new System.Variant(pValue);
                    return;

                case 13:
                    v = new System.Variant(new UnknownWrapper(pValue));
                    return;

                case 0x24:
                    v = new System.Variant(pValue);
                    return;
            }
            throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
        }
        internal static void MarshalHelperConvertObjectToVariant(object o, ref System.Variant v)
        {
            IConvertible convertible = RemotingServices.IsTransparentProxy(o) ? null : (o as IConvertible);
            if (o == null)
            {
                v = Empty;
            }
            else if (convertible == null)
            {
                v = new System.Variant(o);
            }
            else
            {
                IFormatProvider invariantCulture = CultureInfo.InvariantCulture;
                switch (convertible.GetTypeCode())
                {
                    case TypeCode.Empty:
                        v = Empty;
                        return;

                    case TypeCode.Object:
                        v = new System.Variant(o);
                        return;

                    case TypeCode.DBNull:
                        v = DBNull;
                        return;

                    case TypeCode.Boolean:
                        v = new System.Variant(convertible.ToBoolean(invariantCulture));
                        return;

                    case TypeCode.Char:
                        v = new System.Variant(convertible.ToChar(invariantCulture));
                        return;

                    case TypeCode.SByte:
                        v = new System.Variant(convertible.ToSByte(invariantCulture));
                        return;

                    case TypeCode.Byte:
                        v = new System.Variant(convertible.ToByte(invariantCulture));
                        return;

                    case TypeCode.Int16:
                        v = new System.Variant(convertible.ToInt16(invariantCulture));
                        return;

                    case TypeCode.UInt16:
                        v = new System.Variant(convertible.ToUInt16(invariantCulture));
                        return;

                    case TypeCode.Int32:
                        v = new System.Variant(convertible.ToInt32(invariantCulture));
                        return;

                    case TypeCode.UInt32:
                        v = new System.Variant(convertible.ToUInt32(invariantCulture));
                        return;

                    case TypeCode.Int64:
                        v = new System.Variant(convertible.ToInt64(invariantCulture));
                        return;

                    case TypeCode.UInt64:
                        v = new System.Variant(convertible.ToUInt64(invariantCulture));
                        return;

                    case TypeCode.Single:
                        v = new System.Variant(convertible.ToSingle(invariantCulture));
                        return;

                    case TypeCode.Double:
                        v = new System.Variant(convertible.ToDouble(invariantCulture));
                        return;

                    case TypeCode.Decimal:
                        v = new System.Variant(convertible.ToDecimal(invariantCulture));
                        return;

                    case TypeCode.DateTime:
                        v = new System.Variant(convertible.ToDateTime(invariantCulture));
                        return;

                    case TypeCode.String:
                        v = new System.Variant(convertible.ToString(invariantCulture));
                        return;
                }
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnknownTypeCode", new object[] { convertible.GetTypeCode() }));
            }
        }
Exemplo n.º 7
0
        internal static void MarshalHelperCastVariant(object pValue, int vt, ref System.Variant v)
        {
            IConvertible convertible = pValue as IConvertible;

            if (convertible != null)
            {
                IFormatProvider invariantCulture = CultureInfo.InvariantCulture;
                switch (vt)
                {
                case 0:
                    v = Empty;
                    return;

                case 1:
                    v = DBNull;
                    return;

                case 2:
                    v = new System.Variant(convertible.ToInt16(invariantCulture));
                    return;

                case 3:
                    v = new System.Variant(convertible.ToInt32(invariantCulture));
                    return;

                case 4:
                    v = new System.Variant(convertible.ToSingle(invariantCulture));
                    return;

                case 5:
                    v = new System.Variant(convertible.ToDouble(invariantCulture));
                    return;

                case 6:
                    v = new System.Variant(new CurrencyWrapper(convertible.ToDecimal(invariantCulture)));
                    return;

                case 7:
                    v = new System.Variant(convertible.ToDateTime(invariantCulture));
                    return;

                case 8:
                    v = new System.Variant(convertible.ToString(invariantCulture));
                    return;

                case 9:
                    v = new System.Variant(new DispatchWrapper(convertible));
                    return;

                case 10:
                    v = new System.Variant(new ErrorWrapper(convertible.ToInt32(invariantCulture)));
                    return;

                case 11:
                    v = new System.Variant(convertible.ToBoolean(invariantCulture));
                    return;

                case 12:
                    v = new System.Variant(convertible);
                    return;

                case 13:
                    v = new System.Variant(new UnknownWrapper(convertible));
                    return;

                case 14:
                    v = new System.Variant(convertible.ToDecimal(invariantCulture));
                    return;

                case 0x10:
                    v = new System.Variant(convertible.ToSByte(invariantCulture));
                    return;

                case 0x11:
                    v = new System.Variant(convertible.ToByte(invariantCulture));
                    return;

                case 0x12:
                    v = new System.Variant(convertible.ToUInt16(invariantCulture));
                    return;

                case 0x13:
                    v = new System.Variant(convertible.ToUInt32(invariantCulture));
                    return;

                case 20:
                    v = new System.Variant(convertible.ToInt64(invariantCulture));
                    return;

                case 0x15:
                    v = new System.Variant(convertible.ToUInt64(invariantCulture));
                    return;

                case 0x16:
                    v = new System.Variant(convertible.ToInt32(invariantCulture));
                    return;

                case 0x17:
                    v = new System.Variant(convertible.ToUInt32(invariantCulture));
                    return;
                }
                throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
            }
            switch (vt)
            {
            case 8:
                if (pValue != null)
                {
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
                }
                v         = new System.Variant(null);
                v.m_flags = 14;
                return;

            case 9:
                v = new System.Variant(new DispatchWrapper(pValue));
                return;

            case 12:
                v = new System.Variant(pValue);
                return;

            case 13:
                v = new System.Variant(new UnknownWrapper(pValue));
                return;

            case 0x24:
                v = new System.Variant(pValue);
                return;
            }
            throw new InvalidCastException(Environment.GetResourceString("InvalidCast_CannotCoerceByRefVariant"));
        }
Exemplo n.º 8
0
 internal static object MarshalHelperConvertVariantToObject(ref System.Variant v)
 {
     return(v.ToObject());
 }
Exemplo n.º 9
0
        internal static void MarshalHelperConvertObjectToVariant(object o, ref System.Variant v)
        {
            IConvertible convertible = RemotingServices.IsTransparentProxy(o) ? null : (o as IConvertible);

            if (o == null)
            {
                v = Empty;
            }
            else if (convertible == null)
            {
                v = new System.Variant(o);
            }
            else
            {
                IFormatProvider invariantCulture = CultureInfo.InvariantCulture;
                switch (convertible.GetTypeCode())
                {
                case TypeCode.Empty:
                    v = Empty;
                    return;

                case TypeCode.Object:
                    v = new System.Variant(o);
                    return;

                case TypeCode.DBNull:
                    v = DBNull;
                    return;

                case TypeCode.Boolean:
                    v = new System.Variant(convertible.ToBoolean(invariantCulture));
                    return;

                case TypeCode.Char:
                    v = new System.Variant(convertible.ToChar(invariantCulture));
                    return;

                case TypeCode.SByte:
                    v = new System.Variant(convertible.ToSByte(invariantCulture));
                    return;

                case TypeCode.Byte:
                    v = new System.Variant(convertible.ToByte(invariantCulture));
                    return;

                case TypeCode.Int16:
                    v = new System.Variant(convertible.ToInt16(invariantCulture));
                    return;

                case TypeCode.UInt16:
                    v = new System.Variant(convertible.ToUInt16(invariantCulture));
                    return;

                case TypeCode.Int32:
                    v = new System.Variant(convertible.ToInt32(invariantCulture));
                    return;

                case TypeCode.UInt32:
                    v = new System.Variant(convertible.ToUInt32(invariantCulture));
                    return;

                case TypeCode.Int64:
                    v = new System.Variant(convertible.ToInt64(invariantCulture));
                    return;

                case TypeCode.UInt64:
                    v = new System.Variant(convertible.ToUInt64(invariantCulture));
                    return;

                case TypeCode.Single:
                    v = new System.Variant(convertible.ToSingle(invariantCulture));
                    return;

                case TypeCode.Double:
                    v = new System.Variant(convertible.ToDouble(invariantCulture));
                    return;

                case TypeCode.Decimal:
                    v = new System.Variant(convertible.ToDecimal(invariantCulture));
                    return;

                case TypeCode.DateTime:
                    v = new System.Variant(convertible.ToDateTime(invariantCulture));
                    return;

                case TypeCode.String:
                    v = new System.Variant(convertible.ToString(invariantCulture));
                    return;
                }
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnknownTypeCode", new object[] { convertible.GetTypeCode() }));
            }
        }