@@ -13,13 +13,13 @@ static class SerializerHelper
1313 {
1414 public static object Deserialize ( this string input , Type type )
1515 {
16- type = Nullable . GetUnderlyingType ( type ) ?? type ;
17-
1816 if ( string . IsNullOrEmpty ( input ) )
1917 {
2018 return type . GetDefaultValue ( ) ;
2119 }
2220
21+ type = Nullable . GetUnderlyingType ( type ) ?? type ;
22+
2323 if ( type == typeof ( DateTimeOffset ) )
2424 {
2525 return DateTimeOffset . Parse ( input , CultureInfo . InvariantCulture ) ;
@@ -29,12 +29,12 @@ public static object Deserialize(this string input, Type type)
2929 {
3030 return TimeSpan . Parse ( input , CultureInfo . InvariantCulture ) ;
3131 }
32-
32+
3333 if ( type == typeof ( Guid ) )
3434 {
3535 return Guid . Parse ( input ) ;
3636 }
37-
37+
3838 if ( type . IsArray )
3939 {
4040 Type arrType = type . GetElementType ( ) ;
@@ -47,7 +47,11 @@ public static object Deserialize(this string input, Type type)
4747
4848 return arr . ToArray ( ) ;
4949 }
50-
50+
51+ if ( type . IsEnum )
52+ {
53+ return Enum . Parse ( type , input ) ;
54+ }
5155
5256 return Convert . ChangeType ( input , type , CultureInfo . InvariantCulture ) ;
5357 }
@@ -60,7 +64,7 @@ public static string Serialize(this object input)
6064 {
6165 string result = "" ;
6266
63- object [ ] arr = ( object [ ] ) input ;
67+ object [ ] arr = ( object [ ] ) input ;
6468
6569 for ( int i = 0 ; i < arr . Length ; i ++ )
6670 {
@@ -75,19 +79,22 @@ public static string Serialize(this object input)
7579 return result ;
7680 }
7781
78- return input is IFormattable formattable ? formattable . ToString ( null , CultureInfo . InvariantCulture ) : input . ToString ( ) ;
79- }
82+ return input is IFormattable formattable
83+ ? formattable . ToString ( null , CultureInfo . InvariantCulture )
84+ : input . ToString ( ) ;
85+ }
8086
8187 return "" ;
8288 }
8389
84- public static TKey GetKey < TKey , T > ( IPrincipalKeyValueFactory < T > keyValueFactory , IEntityType entityType , Func < string , string > valueSelector )
90+ public static TKey GetKey < TKey , T > ( IPrincipalKeyValueFactory < T > keyValueFactory , IEntityType entityType ,
91+ Func < string , string > valueSelector )
8592 {
86- return ( TKey ) keyValueFactory . CreateFromKeyValues (
93+ return ( TKey ) keyValueFactory . CreateFromKeyValues (
8794 entityType . FindPrimaryKey ( ) . Properties
8895 . Select ( p =>
8996 valueSelector ( p . GetColumnName ( ) )
9097 . Deserialize ( p . GetValueConverter ( ) ? . ProviderClrType ?? p . ClrType ) ) . ToArray ( ) ) ;
9198 }
9299 }
93- }
100+ }
0 commit comments