public static T?Get <T>(this IJsonModel self, string key) { JToken?token = self.Get(key); if (token is null) { return(default);
public IJsonModel ReadJson(IJsonModel model, StreamReader reader) { try { string jsonFromFile; using (reader)) { jsonFromFile = reader.ReadToEnd(); } status = JsonConvert.DeserializeObject<model>(jsonFromFile); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return status; }
public static bool Remove(this IJsonModel self, string key, out JToken?item) { self.AdditionalData ??= new Dictionary <string, JToken?>(); self.AdditionalData.TryGetValue(key, out item); return(self.AdditionalData.Remove(key)); }
public static bool Remove(this IJsonModel self, string key) { self.AdditionalData ??= new Dictionary <string, JToken?>(); return(self.AdditionalData.Remove(key)); }
public static bool Contains(this IJsonModel self, string key) => self.AdditionalData?.ContainsKey(key) ?? false;
public static void Add(this IJsonModel self, string key, JToken?item) { self.AdditionalData ??= new Dictionary <string, JToken?>(); self.AdditionalData.Add(key, item); }
public static void Add(this IJsonModel self, string key, object item) => self.Add(key, JToken.FromObject(item));
public static void SetAdditionalData(this IJsonModel model, IDictionary <string, JToken?>?data) => model.AdditionalData = data;
public static IDictionary <string, JToken?>?GetAdditionalData(this IJsonModel model) => model.AdditionalData;
public static IDictionary <string, JToken?> GetData(this IJsonModel model) => model.GetAdditionalData() ?? new Dictionary <string, JToken?>();
public static HttpResponseMessage Response200Json(IJsonModel model) { return(Response200Json(JsonConvert.SerializeObject(model))); }