System.ComponentModel.NullableConverter.ConvertFrom C# (CSharp) Method

ConvertFrom() public method

public ConvertFrom ( ITypeDescriptorContext context, CultureInfo culture, object value ) : object
context ITypeDescriptorContext
culture System.Globalization.CultureInfo
value object
return object
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
            if (value == null || value.GetType() == this.simpleType) {
                return value;
            }
            else if (value is String && String.IsNullOrEmpty(value as String)) {
                return null;
            }
            else if (this.simpleTypeConverter != null) {
                object convertedValue = this.simpleTypeConverter.ConvertFrom(context, culture, value);
                return convertedValue;
            }
            else {
                return base.ConvertFrom(context, culture, value);
            }
        }

Usage Example

Esempio n. 1
0
        private TypeMath(Type valueType)
        {
            if (!TypeInfo.IsNumericType(valueType))
                throw new Exception("Numeric type is required for math!");

            Min = TypeMathExpressionHelper.GetMinDelegate<BinOp>(valueType, typeof(object));
            Max = TypeMathExpressionHelper.GetMaxDelegate<BinOp>(valueType, typeof(object));

            Sum = TypeMathExpressionHelper.GetSumDelegate<BinOp>(valueType, typeof(object));
            Multiply = TypeMathExpressionHelper.GetMultiplyDelegate<BinOp>(valueType, typeof(object));

            if (TypeInfo.IsNullableType(valueType))
            {
                var nc = new NullableConverter(valueType);
                Zero = nc.ConvertFrom(Convert.ChangeType(0, Nullable.GetUnderlyingType(valueType)));
                One = nc.ConvertFrom(Convert.ChangeType(1, Nullable.GetUnderlyingType(valueType)));
                SumNullAsZero = TypeMathExpressionHelper.GetSumIsNullDelegate<BinOp>(valueType, typeof(object), Zero);
                MultiplyNullAsOne = TypeMathExpressionHelper.GetMultiplyIsNullDelegate<BinOp>(valueType, typeof(object), One);
            }
            else
            {
                Zero = Convert.ChangeType(0, valueType);
                One = Convert.ChangeType(1, valueType);
                SumNullAsZero = Sum;
                MultiplyNullAsOne = Multiply;
            }
        }
All Usage Examples Of System.ComponentModel.NullableConverter::ConvertFrom