コード例 #1
0
        public static bool FromObjToNumericType <N>(object fromObj, N defaultVal, Type xType, out object result)
        {
            var valueUpdated = true;

            result = defaultVal;

            if (xType == TypeClass.ByteClass)
            {
                result = NumericConv.ObjectToByte(fromObj, NumericConv.ObjectToByte(defaultVal));
            }
            else if (xType == TypeClass.SByteClass)
            {
                result = NumericConv.ObjectToSByte(fromObj, NumericConv.ObjectToSByte(defaultVal));
            }
            else if (xType == TypeClass.Int16Class)
            {
                result = NumericConv.ObjectToInt16(fromObj, NumericConv.ObjectToInt16(defaultVal));
            }
            else if (xType == TypeClass.UInt16Class)
            {
                result = NumericConv.ObjectToUInt16(fromObj, NumericConv.ObjectToUInt16(defaultVal));
            }
            else if (xType == TypeClass.Int32Class)
            {
                result = NumericConv.ObjectToInt32(fromObj, NumericConv.ObjectToInt32(defaultVal));
            }
            else if (xType == TypeClass.UInt32Class)
            {
                result = NumericConv.ObjectToUInt32(fromObj, NumericConv.ObjectToUInt32(defaultVal));
            }
            else if (xType == TypeClass.Int64Class)
            {
                result = NumericConv.ObjectToInt64(fromObj, NumericConv.ObjectToInt64(defaultVal));
            }
            else if (xType == TypeClass.UInt64Class)
            {
                result = NumericConv.ObjectToUInt64(fromObj, NumericConv.ObjectToUInt64(defaultVal));
            }
            else if (xType == TypeClass.FloatClass)
            {
                result = NumericConv.ObjectToFloat(fromObj, NumericConv.ObjectToFloat(defaultVal));
            }
            else if (xType == TypeClass.DoubleClass)
            {
                result = NumericConv.ObjectToDouble(fromObj, NumericConv.ObjectToDouble(defaultVal));
            }
            else if (xType == TypeClass.DecimalClass)
            {
                result = NumericConv.ObjectToDecimal(fromObj, NumericConv.ObjectToDecimal(defaultVal));
            }
            else
            {
                valueUpdated = false;
            }

            return(valueUpdated);
        }
コード例 #2
0
        private static bool FromObjToNullableNumericType(object fromObj, Type innerType, out object result)
        {
            var valueUpdated = true;

            result = null;

            if (innerType == TypeClass.ByteClass)
            {
                result = NumericConv.ObjectToNullableByte(fromObj);
            }
            else if (innerType == TypeClass.SByteClass)
            {
                result = NumericConv.ObjectToNullableSByte(fromObj);
            }
            else if (innerType == TypeClass.Int16Class)
            {
                result = NumericConv.ObjectToNullableInt16(fromObj);
            }
            else if (innerType == TypeClass.UInt16Class)
            {
                result = NumericConv.ObjectToNullableInt16(fromObj);
            }
            else if (innerType == TypeClass.Int32Class)
            {
                result = NumericConv.ObjectToNullableInt32(fromObj);
            }
            else if (innerType == TypeClass.UInt32Class)
            {
                result = NumericConv.ObjectToNullableUInt32(fromObj);
            }
            else if (innerType == TypeClass.Int64Class)
            {
                result = NumericConv.ObjectToNullableInt64(fromObj);
            }
            else if (innerType == TypeClass.UInt64Class)
            {
                result = NumericConv.ObjectToNullableUInt64(fromObj);
            }
            else if (innerType == TypeClass.FloatClass)
            {
                result = NumericConv.ObjectToNullableFloat(fromObj);
            }
            else if (innerType == TypeClass.DoubleClass)
            {
                result = NumericConv.ObjectToNullableDouble(fromObj);
            }
            else if (innerType == TypeClass.DecimalClass)
            {
                result = NumericConv.ObjectToNullableDecimal(fromObj);
            }
            else
            {
                valueUpdated = false;
            }

            return(valueUpdated);
        }
コード例 #3
0
        private static bool FromNullableNumericTypeToString(object numericVal, Type oType, CastingContext context, out object result)
        {
            var valueUpdated = true;

            result = null;

            if (oType == TypeClass.Int16NullableClass)
            {
                result = StringConv.Int16ToString(NumericConv.ObjectToNullableInt16(numericVal), string.Empty);
            }
            else if (oType == TypeClass.UInt16NullableClass)
            {
                result = StringConv.UInt16ToString(NumericConv.ObjectToNullableUInt16(numericVal), string.Empty);
            }
            else if (oType == TypeClass.Int32NullableClass)
            {
                result = StringConv.Int32ToString(NumericConv.ObjectToNullableInt32(numericVal), string.Empty);
            }
            else if (oType == TypeClass.UInt32NullableClass)
            {
                result = StringConv.UInt32ToString(NumericConv.ObjectToNullableUInt32(numericVal), string.Empty);
            }
            else if (oType == TypeClass.Int64NullableClass)
            {
                result = StringConv.Int64ToString(NumericConv.ObjectToNullableInt64(numericVal), string.Empty);
            }
            else if (oType == TypeClass.UInt64NullableClass)
            {
                result = StringConv.UInt64ToString(NumericConv.ObjectToNullableUInt64(numericVal), string.Empty);
            }
            else if (oType == TypeClass.FloatNullableClass)
            {
                result = StringConv.FloatToString(NumericConv.ObjectToNullableFloat(numericVal), context.Digits);
            }
            else if (oType == TypeClass.DoubleNullableClass)
            {
                result = StringConv.DoubleToString(NumericConv.ObjectToNullableDouble(numericVal), context.Digits);
            }
            else if (oType == TypeClass.DecimalNullableClass)
            {
                result = StringConv.DecimalToString(NumericConv.ObjectToNullableDecimal(numericVal), context.Digits, string.Empty);
            }
            else
            {
                valueUpdated = false;
            }

            return(valueUpdated);
        }
コード例 #4
0
        private static bool FromEnumToNumericType <N>(Type enumType, object enumVal, N defaultVal, Type xType, out object result)
        {
            var valueUpdated = true;

            result = defaultVal;

            if (xType == TypeClass.ByteClass)
            {
                result = NumericConv.EnumToByte(enumType, enumVal, NumericConv.ObjectToByte(defaultVal));
            }
            else if (xType == TypeClass.SByteClass)
            {
                result = NumericConv.EnumToSByte(enumType, enumVal, NumericConv.ObjectToSByte(defaultVal));
            }
            else if (xType == TypeClass.Int16Class)
            {
                result = NumericConv.EnumToInt16(enumType, enumVal, NumericConv.ObjectToInt16(defaultVal));
            }
            else if (xType == TypeClass.UInt16Class)
            {
                result = NumericConv.EnumToUInt16(enumType, enumVal, NumericConv.ObjectToUInt16(defaultVal));
            }
            else if (xType == TypeClass.Int32Class)
            {
                result = NumericConv.EnumToInt32(enumType, enumVal, NumericConv.ObjectToInt32(defaultVal));
            }
            else if (xType == TypeClass.UInt32Class)
            {
                result = NumericConv.EnumToUInt32(enumType, enumVal, NumericConv.ObjectToUInt32(defaultVal));
            }
            else if (xType == TypeClass.Int64Class)
            {
                result = NumericConv.EnumToInt64(enumType, enumVal, NumericConv.ObjectToInt64(defaultVal));
            }
            else if (xType == TypeClass.UInt32Class)
            {
                result = NumericConv.EnumToUInt64(enumType, enumVal, NumericConv.ObjectToUInt64(defaultVal));
            }
            else
            {
                valueUpdated = false;
            }

            return(valueUpdated);
        }
コード例 #5
0
        private static bool FromEnumToNullableNumericType(Type enumType, object @enum, Type xType, out object result)
        {
            var valueUpdated = true;

            result = null;

            if (xType == TypeClass.ByteClass)
            {
                result = NumericConv.EnumToNullableByte(enumType, @enum);
            }
            else if (xType == TypeClass.SByteClass)
            {
                result = NumericConv.EnumToNullableSByte(enumType, @enum);
            }
            else if (xType == TypeClass.Int16Class)
            {
                result = NumericConv.EnumToNullableInt16(enumType, @enum);
            }
            else if (xType == TypeClass.UInt16Class)
            {
                result = NumericConv.EnumToNullableUInt16(enumType, @enum);
            }
            else if (xType == TypeClass.Int32Class)
            {
                result = NumericConv.EnumToNullableInt32(enumType, @enum);
            }
            else if (xType == TypeClass.UInt32Class)
            {
                result = NumericConv.EnumToNullableUInt32(enumType, @enum);
            }
            else if (xType == TypeClass.Int64Class)
            {
                result = NumericConv.EnumToNullableInt64(enumType, @enum);
            }
            else if (xType == TypeClass.UInt64Class)
            {
                result = NumericConv.EnumToNullableUInt64(enumType, @enum);
            }
            else
            {
                valueUpdated = false;
            }

            return(valueUpdated);
        }