Src/Black.Beard.ComponentModel/ComponentModel/Accessors/MyConverter.cs
/// <summary>
/// Serializes the specified value in string.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
Serializes the specified value in string.
Serializes the specified value in string .
public static string Serialize(dynamic value)
        {
            if (value == null)
                return Default;
            switch (value)
            {
                case byte _b1:
                    return _b1.ToString(CultureInfo.CurrentCulture);
                case sbyte _b10:
                    return _b10.ToString(CultureInfo.CurrentCulture);
                case decimal _b4:
                    return _b4.ToString(CultureInfo.CurrentCulture);
                case float _b9:
                    return _b9.ToString(CultureInfo.CurrentCulture);
                case double _b5:
                    return _b5.ToString(CultureInfo.CurrentCulture);
                case ushort _b6:
                    return _b6.ToString(CultureInfo.CurrentCulture);
                case short _b13:
                    return _b13.ToString(CultureInfo.CurrentCulture);
                case uint _b7:
                    return _b7.ToString(CultureInfo.CurrentCulture);
                case int _b11:
                    return _b11.ToString(CultureInfo.CurrentCulture);
                case ulong _b8:
                    return _b8.ToString(CultureInfo.CurrentCulture);
                case long _b12:
                    return _b12.ToString(CultureInfo.CurrentCulture);
                case DateTime _b5:
                case bool _b2:
                    return value.ToString();
                case char _b3:
                    return char.ToString(_b3);
                case string _b11:
                    return _b11;
                default:
                    break;
            }
            Type type = value.GetType();
            if (type.IsEnum)
                return value.ToString();
            if (type == typeof(bool) || type == typeof(bool?))
                return value.ToString();
            if (type == typeof(byte) || type == typeof(byte?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(char) || type == typeof(char?))
                return char.ToString(value);
            if (type == typeof(DateTime) || type == typeof(DateTime?))
                return value.ToString();
            if (type == typeof(decimal) || type == typeof(decimal?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(double) || type == typeof(double?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(short) || type == typeof(short?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(int) || type == typeof(int?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(long) || type == typeof(long?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(sbyte) || type == typeof(sbyte?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(float) || type == typeof(float?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(string))
                return value.ToString();
            if (type == typeof(ushort) || type == typeof(ushort?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(uint) || type == typeof(uint?))
                return value.ToString(CultureInfo.CurrentCulture);
            if (type == typeof(ulong) || type == typeof(ulong?))
                return value.ToString(CultureInfo.CurrentCulture);
            IConvertible convertible = value as IConvertible;
            if (convertible != null)
                return convertible.ToString(CultureInfo.CurrentCulture);
            IFormattable formattable = value as IFormattable;
            if (formattable != null)
                return formattable.ToString(null, CultureInfo.CurrentCulture);
            var c = TypeDescriptor.GetConverter(value.GetType());
            string result = c.ConvertTo(value, typeof(string)) as string;
            return result;
        }
public static string Serialize ( dynamic value ) { if ( value == null ) return Default ; switch ( value ) { case byte _b1 : return _b1 . ToString ( CultureInfo . CurrentCulture ) ; case sbyte _b10 : return _b10 . ToString ( CultureInfo . CurrentCulture ) ; case decimal _b4 : return _b4 . ToString ( CultureInfo . CurrentCulture ) ; case float _b9 : return _b9 . ToString ( CultureInfo . CurrentCulture ) ; case double _b5 : return _b5 . ToString ( CultureInfo . CurrentCulture ) ; case ushort _b6 : return _b6 . ToString ( CultureInfo . CurrentCulture ) ; case short _b13 : return _b13 . ToString ( CultureInfo . CurrentCulture ) ; case uint _b7 : return _b7 . ToString ( CultureInfo . CurrentCulture ) ; case int _b11 : return _b11 . ToString ( CultureInfo . CurrentCulture ) ; case ulong _b8 : return _b8 . ToString ( CultureInfo . CurrentCulture ) ; case long _b12 : return _b12 . ToString ( CultureInfo . CurrentCulture ) ; case DateTime _b5 : case bool _b2 : return value . ToString ( ) ; case char _b3 : return char . ToString ( _b3 ) ; case string _b11 : return _b11 ; default : break ; } Type type = value . GetType ( ) ; if ( type . IsEnum ) return value . ToString ( ) ; if ( type == typeof ( bool ) || type == typeof ( bool ? ) ) return value . ToString ( ) ; if ( type == typeof ( byte ) || type == typeof ( byte ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( char ) || type == typeof ( char ? ) ) return char . ToString ( value ) ; if ( type == typeof ( DateTime ) || type == typeof ( DateTime ? ) ) return value . ToString ( ) ; if ( type == typeof ( decimal ) || type == typeof ( decimal ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( double ) || type == typeof ( double ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( short ) || type == typeof ( short ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( int ) || type == typeof ( int ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( long ) || type == typeof ( long ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( sbyte ) || type == typeof ( sbyte ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( float ) || type == typeof ( float ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( string ) ) return value . ToString ( ) ; if ( type == typeof ( ushort ) || type == typeof ( ushort ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( uint ) || type == typeof ( uint ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; if ( type == typeof ( ulong ) || type == typeof ( ulong ? ) ) return value . ToString ( CultureInfo . CurrentCulture ) ; IConvertible convertible = value as IConvertible ; if ( convertible != null ) return convertible . ToString ( CultureInfo . CurrentCulture ) ; IFormattable formattable = value as IFormattable ; if ( formattable != null ) return formattable . ToString ( null , CultureInfo . CurrentCulture ) ; var c = TypeDescriptor . GetConverter ( value . GetType ( ) ) ; string result = c . ConvertTo ( value , typeof ( string ) ) as string ; return result ; }
Serializes the specified value in string.
Serializes the specified value in string .
None
value
dynamic
None