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

            return((JObject)token);
        }