Example #1
0
        public static object FormatObject(
            object value,
            System.Type targetType,
            TypeConverter sourceConverter,
            TypeConverter targetConverter,
            string formatString,
            IFormatProvider formatInfo,
            object formattedNullValue,
            object dataSourceNullValue)
        {
            if (Formatter.IsNullData(value, dataSourceNullValue))
            {
                value = (object)DBNull.Value;
            }
            System.Type type = targetType;
            targetType      = Formatter.NullableUnwrap(targetType);
            sourceConverter = Formatter.NullableUnwrap(sourceConverter);
            targetConverter = Formatter.NullableUnwrap(targetConverter);
            bool   flag = (object)targetType != (object)type;
            object obj  = Formatter.FormatObjectInternal(value, targetType, sourceConverter, targetConverter, formatString, formatInfo, formattedNullValue);

            if (type.IsValueType && obj == null && !flag)
            {
                throw new FormatException(Formatter.GetCantConvertMessage(value, targetType));
            }
            return(obj);
        }
Example #2
0
        public static object ParseObject(object value, System.Type targetType, System.Type sourceType, TypeConverter targetConverter, TypeConverter sourceConverter, IFormatProvider formatInfo, object formattedNullValue, object dataSourceNullValue)
        {
            System.Type type1 = targetType;
            sourceType      = Formatter.NullableUnwrap(sourceType);
            targetType      = Formatter.NullableUnwrap(targetType);
            sourceConverter = Formatter.NullableUnwrap(sourceConverter);
            targetConverter = Formatter.NullableUnwrap(targetConverter);
            object obj1 = Formatter.ParseObjectInternal(value, targetType, sourceType, targetConverter, sourceConverter, formatInfo, formattedNullValue);

            if (obj1 == DBNull.Value)
            {
                return(Formatter.NullData(type1, dataSourceNullValue));
            }
            return(obj1);
        }