public static T RetrievePropertyAs <T>(this JObject json, string propertyName) where T : JToken { Assert.NotNull(json); var property = json[propertyName]; Assert.NotNull(property); DthMessageExtension.AssertType <T>(property, $"Property {propertyName}"); return((T)property); }
public static T RetrieveArraryElementAs <T>(this JArray json, int index) where T : JToken { Assert.NotNull(json); Assert.True(index >= 0 && index < json.Count, "Index out of range"); var element = json[index]; DthMessageExtension.AssertType <T>(element, $"Element at {index}"); return((T)element); }
public static JObject AsJObject(this JToken token) { DthMessageExtension.AssertType <JObject>(token, nameof(JToken)); return((JObject)token); }