Пример #1
0
    public static T?Get <T>(this IJsonModel self, string key)
    {
        JToken?token = self.Get(key);

        if (token is null)
        {
            return(default);
Пример #2
0
         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;
         }
Пример #3
0
 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));
 }
Пример #4
0
 public static bool Remove(this IJsonModel self, string key)
 {
     self.AdditionalData ??= new Dictionary <string, JToken?>();
     return(self.AdditionalData.Remove(key));
 }
Пример #5
0
 public static bool Contains(this IJsonModel self, string key) => self.AdditionalData?.ContainsKey(key) ?? false;
Пример #6
0
 public static void Add(this IJsonModel self, string key, JToken?item)
 {
     self.AdditionalData ??= new Dictionary <string, JToken?>();
     self.AdditionalData.Add(key, item);
 }
Пример #7
0
 public static void Add(this IJsonModel self, string key, object item) => self.Add(key, JToken.FromObject(item));
Пример #8
0
 public static void                          SetAdditionalData(this IJsonModel model, IDictionary <string, JToken?>?data) => model.AdditionalData = data;
Пример #9
0
 public static IDictionary <string, JToken?>?GetAdditionalData(this IJsonModel model) => model.AdditionalData;
Пример #10
0
 public static IDictionary <string, JToken?> GetData(this           IJsonModel model) => model.GetAdditionalData() ?? new Dictionary <string, JToken?>();
Пример #11
0
 public static HttpResponseMessage Response200Json(IJsonModel model)
 {
     return(Response200Json(JsonConvert.SerializeObject(model)));
 }