예제 #1
0
        private static JToken Serialize(object o)
        {
            var tne = new TypeNameEncapsulator {
                o = o
            };

            return(JToken.FromObject(tne, ConfigService.Serializer)["o"]);
        }
예제 #2
0
 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);
         }
 }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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());
        }
예제 #6
0
 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);
             }
         }
 }