예제 #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));
        }
예제 #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));
        }
예제 #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));
        }
예제 #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);
        }
예제 #5
0
        public void SerializeFile(string filePath, object value, NbJsonSerializeConfig config = null)
        {
            string jsonValue = Serialize(value, config);

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