Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        public static JObject AsJObject(this JToken token)
        {
            DthMessageExtension.AssertType <JObject>(token, nameof(JToken));

            return((JObject)token);
        }