File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed
src/GoatQuery/src/Evaluator Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -621,22 +621,26 @@ private static Result<ConstantExpression> CreateStringOrEnumConstant(string valu
621621
622622 private static Result < ConstantExpression > ConvertStringToEnum ( string value , Type actualType , Type targetType )
623623 {
624- if ( Enum . TryParse ( actualType , value , out var enumValue ) )
624+ try
625625 {
626+ var enumValue = Enum . Parse ( actualType , value , true ) ;
627+
626628 return Result . Ok ( Expression . Constant ( enumValue , targetType ) ) ;
627629 }
628-
629- foreach ( var field in actualType . GetFields ( BindingFlags . Public | BindingFlags . Static ) )
630+ catch ( Exception )
630631 {
631- var memberNameAttribute = field . GetCustomAttribute < JsonStringEnumMemberNameAttribute > ( ) ;
632-
633- if ( memberNameAttribute != null && memberNameAttribute . Name . Equals ( value , StringComparison . Ordinal ) )
632+ foreach ( var field in actualType . GetFields ( BindingFlags . Public | BindingFlags . Static ) )
634633 {
635- return Result . Ok ( Expression . Constant ( field . GetValue ( null ) , targetType ) ) ;
634+ var memberNameAttribute = field . GetCustomAttribute < JsonStringEnumMemberNameAttribute > ( ) ;
635+
636+ if ( memberNameAttribute != null && memberNameAttribute . Name . Equals ( value , StringComparison . Ordinal ) )
637+ {
638+ return Result . Ok ( Expression . Constant ( field . GetValue ( null ) , targetType ) ) ;
639+ }
636640 }
637- }
638641
639- return Result . Fail ( $ "Value '{ value } ' is not a valid member of enum { actualType . Name } ") ;
642+ return Result . Fail ( $ "Value '{ value } ' is not a valid member of enum { actualType . Name } ") ;
643+ }
640644 }
641645
642646 private static Type GetNonNullableType ( Type type )
You can’t perform that action at this time.
0 commit comments