Explorar o código

Fix for parsing flag enums

Brad Robinson %!s(int64=10) %!d(string=hai) anos
pai
achega
ce08696b47
Modificáronse 1 ficheiros con 10 adicións e 1 borrados
  1. 10 1
      PetaJson.cs

+ 10 - 1
PetaJson.cs

@@ -844,7 +844,16 @@ namespace PetaJson
                 if (type.IsEnum)
                 {
                     if (type.GetCustomAttributes(typeof(FlagsAttribute), false).Any())
-                        return ReadLiteral(literal => Enum.ToObject(type, literal));
+                        return ReadLiteral(literal => {
+                            try
+                            {
+                                return Enum.Parse(type, (string)literal);
+                            }
+                            catch
+                            {
+                                return Enum.ToObject(type, literal);
+                            }
+                        });
                     else
                         return ReadLiteral(literal => Enum.Parse(type, (string)literal));
                 }