Ver código fonte

Fix for parsing flag enums

Brad Robinson 10 anos atrás
pai
commit
ce08696b47
1 arquivos alterados com 10 adições e 1 exclusões
  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));
                 }