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)); }
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)); }
public string Serialize(object value, NbJsonSerializeConfig config = null) { if (config == null) { return(JsonConvert.SerializeObject(value)); } var settings = ConvertSettings(config); return(JsonConvert.SerializeObject(value, settings)); }
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); }
public void SerializeFile(string filePath, object value, NbJsonSerializeConfig config = null) { string jsonValue = Serialize(value, config); File.WriteAllText(filePath, jsonValue, Encoding.UTF8); }