private static JToken Serialize(object o) { var tne = new TypeNameEncapsulator { o = o }; return(JToken.FromObject(tne, ConfigService.Serializer)["o"]); }
public static object LoadWithType(string serialized) { using (TextReader tr = new StringReader(serialized)) using (JsonTextReader jr = new JsonTextReader(tr)) { TypeNameEncapsulator tne = (TypeNameEncapsulator)Serializer.Deserialize(jr, typeof(TypeNameEncapsulator)); return(tne.o); } }
public static object LoadWithType(string serialized) { using TextReader tr = new StringReader(serialized); using JsonTextReader jr = new JsonTextReader(tr); TypeNameEncapsulator tne = (TypeNameEncapsulator)Serializer.Deserialize(jr, typeof(TypeNameEncapsulator)); // in the case of trying to deserialize nothing, tne will be nothing // we want to return nothing return(tne?.o); }
private static JToken Serialize(object o) { var tne = new TypeNameEncapsulator { o = o }; return(JToken.FromObject(tne, ConfigService.Serializer)["o"]); // Maybe todo: This code is identical to the code above, except that it does not emit the legacy "$type" // parameter that we no longer need here. Leaving that in to make bisecting during this dev phase easier, and such. // return JToken.FromObject(o, ConfigService.Serializer); }
public static string SaveWithType(object o) { using var sw = new StringWriter(); using var jw = new JsonTextWriter(sw) { Formatting = Formatting.None }; var tne = new TypeNameEncapsulator { o = o }; Serializer.Serialize(jw, tne, typeof(TypeNameEncapsulator)); sw.Flush(); return(sw.ToString()); }
public static object LoadWithType(string serialized) { using (TextReader tr = new StringReader(serialized)) using (JsonTextReader jr = new JsonTextReader(tr)) { TypeNameEncapsulator tne = (TypeNameEncapsulator)Serializer.Deserialize(jr, typeof(TypeNameEncapsulator)); // in the case of trying to deserialize nothing, tne will be nothing // we want to return nothing if (tne != null) { return(tne.o); } else { return(null); } } }