Stringify.Library/StringConverter.cs
/// <summary>
/// Converts a string to the desired type using the specified options
/// </summary>
/// <typeparam name="T">Desired output type</typeparam>
/// <param name="value">String value to be converted</param>
/// <param name="options">Converter options to customise</param>
/// <returns>Instance of the desired type</returns>
Converts a string to the desired type using the specified options
Converts a string to the desired type using the specified options
public T ConvertTo<T>(string value, ConverterOptions options)
        {
            var type = typeof(T);
            if (value == null && type.GetTypeInfo().IsClass)
                return default(T);
            if (options == null)
                options = ConverterOptions.Default;
            if (!EnumerableHelper.IsEnumerableType(type))
                return Convert<T>(value, options);
            var enumerable = InvokeGetArray(type, value, options);
            if (type.IsArray || type.GetTypeInfo().IsInterface)
                return (T)enumerable;
            return (T)Activator.CreateInstance(type, enumerable);
        }
public T ConvertTo < T > ( string value , ConverterOptions options ) { var type = typeof ( T ) ; if ( value == null && type . GetTypeInfo ( ) . IsClass ) return default ( T ) ; if ( options == null ) options = ConverterOptions . Default ; if ( ! EnumerableHelper . IsEnumerableType ( type ) ) return Convert < T > ( value , options ) ; var enumerable = InvokeGetArray ( type , value , options ) ; if ( type . IsArray || type . GetTypeInfo ( ) . IsInterface ) return ( T ) enumerable ; return ( T ) Activator . CreateInstance ( type , enumerable ) ; }
Converts a string to the desired type using the specified options
Converts a string to the desired type using the specified options
Instance of the desired type
Instance of the desired type
value
string
String value to be converted
String value to be converted
options
ConverterOptions
Converter options to customise
Converter options to customise
typeparam
Desired output type
Desired output type