Procházet zdrojové kódy

Parse enums without throwing exception

Brad Robinson před 3 roky
rodič
revize
439daf5243
1 změnil soubory, kde provedl 4 přidání a 1 odebrání
  1. 4 1
      Topten.JsonKit/JsonReader.cs

+ 4 - 1
Topten.JsonKit/JsonReader.cs

@@ -275,7 +275,10 @@ namespace Topten.JsonKit
                     return ReadLiteral(literal => {
                         try
                         {
-                            return Enum.Parse(type, (string)literal);
+                            if (literal is string str)
+                                return Enum.Parse(type, str);
+                            else
+                                return Enum.ToObject(type, literal);
                         }
                         catch
                         {