This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
src/ServiceStack.Text/Common
tests/ServiceStack.Text.Tests Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change 1111//
1212
1313using System ;
14+ using System . Linq ;
1415
1516namespace ServiceStack . Text . Common
1617{
@@ -64,7 +65,12 @@ public static Type ParseType(string assemblyQualifiedName)
6465 public static object TryParseEnum ( Type enumType , string str )
6566 {
6667 if ( JsConfig . EmitLowercaseUnderscoreNames )
67- str = str . Replace ( "_" , "" ) ;
68+ {
69+ string [ ] names = Enum . GetNames ( enumType ) ;
70+ if ( ! names . Contains ( str ) ) // does this need StringComparer.InvariantCultureIgnoreCase?
71+ str = str . Replace ( "_" , "" ) ;
72+ }
73+
6874
6975 return Enum . Parse ( enumType , str , ignoreCase : true ) ;
7076 }
Original file line number Diff line number Diff line change @@ -149,10 +149,12 @@ public void Can_serialize_different_enum_styles()
149149 {
150150 Assert . That ( "Word" . FromJson < EnumStyles > ( ) , Is . EqualTo ( EnumStyles . Word ) ) ;
151151 Assert . That ( "DoubleWord" . FromJson < EnumStyles > ( ) , Is . EqualTo ( EnumStyles . DoubleWord ) ) ;
152+ Assert . That ( "Underscore_Words" . FromJson < EnumStyles > ( ) , Is . EqualTo ( EnumStyles . Underscore_Words ) ) ;
152153
153154 using ( JsConfig . With ( emitLowercaseUnderscoreNames : true ) )
154155 {
155156 Assert . That ( "Double_Word" . FromJson < EnumStyles > ( ) , Is . EqualTo ( EnumStyles . DoubleWord ) ) ;
157+ Assert . That ( "Underscore_Words" . FromJson < EnumStyles > ( ) , Is . EqualTo ( EnumStyles . Underscore_Words ) ) ;
156158 }
157159 }
158160 }
You can’t perform that action at this time.
0 commit comments