コード例 #1
0
        /// <summary>
        /// Deserialize the information from the string of a Json file
        /// </summary>
        /// <param name="json"> The Json string to deserialize </param>
        private void DeserializeJson(string json)
        {
            var binder = new TypeNameSerializationBinder("ZeeScherpThreading.FractalTemplate.{0}, ZeeScherpThreading");

            // Deserialize the JSON file.
            var obj = JsonConvert.DeserializeObject <ClassToSerializeViaJson>(json,
                                                                              new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto,
                Binder           = binder
            });

            this.fractals = obj.CollectionToSerialize;
        }
コード例 #2
0
        /// <summary>
        /// Serializes the the fractal templates to insert into a Json file
        /// </summary>
        /// <returns> The serialized string </returns>
        private string SerializeJson()
        {
            // Create a new class to serialize
            var toserialize = new ClassToSerializeViaJson();
            var binder      = new TypeNameSerializationBinder("ZeeScherpThreading.FractalTemplate.{0}, ZeeScherpThreading");

            toserialize.CollectionToSerialize = fractals;

            // Serialize the Object to a string.
            string json = JsonConvert.SerializeObject(toserialize, Formatting.Indented,
                                                      new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto,
                Binder           = binder
            });

            return(json);
        }