@@ -47,11 +47,29 @@ public static T DeserializeObject<T>(string json)
47
47
return DeserializeObject < T > ( json , LootLockerJsonSettings . Default ) ;
48
48
}
49
49
50
-
51
50
public static T DeserializeObject < T > ( string json , JsonSerializerSettings settings )
52
51
{
53
52
return JsonConvert . DeserializeObject < T > ( json , settings ?? LootLockerJsonSettings . Default ) ;
54
53
}
54
+
55
+ public static bool TryDeserializeObject < T > ( string json , out T output )
56
+ {
57
+ return TryDeserializeObject < T > ( json , LootLockerJsonSettings . Default , out output ) ;
58
+ }
59
+
60
+ public static bool TryDeserializeObject < T > ( string json , JsonSerializerSettings options , out T output )
61
+ {
62
+ try
63
+ {
64
+ output = JsonConvert . DeserializeObject < T > ( json , options ?? LootLockerJsonSettings . Default ) ;
65
+ return true ;
66
+ }
67
+ catch ( Exception )
68
+ {
69
+ output = default ( T ) ;
70
+ return false ;
71
+ }
72
+ }
55
73
#else //LOOTLOCKER_USE_NEWTONSOFTJSON
56
74
public static string SerializeObject ( object obj )
57
75
{
@@ -72,6 +90,24 @@ public static T DeserializeObject<T>(string json, JsonOptions options)
72
90
{
73
91
return Json . Deserialize < T > ( json , options ?? LootLockerJsonSettings . Default ) ;
74
92
}
93
+
94
+ public static bool TryDeserializeObject < T > ( string json , out T output )
95
+ {
96
+ return TryDeserializeObject < T > ( json , LootLockerJsonSettings . Default , out output ) ;
97
+ }
98
+
99
+ public static bool TryDeserializeObject < T > ( string json , JsonOptions options , out T output )
100
+ {
101
+ try
102
+ {
103
+ output = Json . Deserialize < T > ( json , options ?? LootLockerJsonSettings . Default ) ;
104
+ return true ;
105
+ } catch ( Exception )
106
+ {
107
+ output = default ( T ) ;
108
+ return false ;
109
+ }
110
+ }
75
111
#endif //LOOTLOCKER_USE_NEWTONSOFTJSON
76
112
}
77
113
0 commit comments