Example #1
0
        public T DeserializeFile <T>(string filePath, NbJsonSerializeConfig config = null)
        {
            //var value = Deserialize<T>(filePath, config);
            string json = File.ReadAllText(filePath);

            return(Deserialize <T>(json, config));
        }
Example #2
0
        public T Deserialize <T>(string json, NbJsonSerializeConfig config = null)
        {
            if (config == null)
            {
                return(JsonConvert.DeserializeObject <T>(json));
            }
            var settings = ConvertSettings(config);

            return(JsonConvert.DeserializeObject <T>(json, settings));
        }
Example #3
0
        public string Serialize(object value, NbJsonSerializeConfig config = null)
        {
            if (config == null)
            {
                return(JsonConvert.SerializeObject(value));
            }
            var settings = ConvertSettings(config);

            return(JsonConvert.SerializeObject(value, settings));
        }
Example #4
0
        private JsonSerializerSettings ConvertSettings(NbJsonSerializeConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            var settings = new JsonSerializerSettings();

            settings.Formatting = (Formatting)config.Formatting;
            if (config.CamelCase)
            {
                settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            }
            return(settings);
        }
Example #5
0
        public void SerializeFile(string filePath, object value, NbJsonSerializeConfig config = null)
        {
            string jsonValue = Serialize(value, config);

            File.WriteAllText(filePath, jsonValue, Encoding.UTF8);
        }