RestImageResize/Utils/SmartConvert.cs
/// <summary>
/// Converts value to the equivalent value of specified type.
/// </summary>
/// <param name="targetType">The target conversion type.</param>
/// <param name="value">The value to convert.</param>
/// <param name="defaultValue">The default value of target type that should be used as empty value equivalent.</param>
/// <returns>
/// The conversion result value.
/// </returns>
Converts value to the equivalent value of specified type.
Converts value to the equivalent value of specified type .
public static object ChangeType(Type targetType, object value, object defaultValue = null)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }
            if (defaultValue != null)
            {
                try
                {
                    defaultValue = ChangeType(targetType, defaultValue);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Default value type mismatch.", "defaultValue", ex);
                }
            }
            return ChangeTypeImpl(targetType, value, defaultValue);
        }
public static object ChangeType ( Type targetType , object value , object defaultValue = null ) { if ( targetType == null ) { throw new ArgumentNullException ( " " ) ; } if ( defaultValue != null ) { try { defaultValue = ChangeType ( targetType , defaultValue ) ; } catch ( Exception ex ) { throw new ArgumentException ( " " , " " , ex ) ; } } return ChangeTypeImpl ( targetType , value , defaultValue ) ; }
Converts value to the equivalent value of specified type.
Converts value to the equivalent value of specified type .
The conversion result value.
The conversion result value .
targetType
Type
The target conversion type.
The target conversion type .
value
object
The value to convert.
The value to convert .
defaultValue
object
The default value of target type that should be used as empty value equivalent.
The default value of target type that should be used as empty value equivalent .