示例#1
0
        public void Evaluate_PropertyIsArray_ReturnsArray()
        {
            var path = new HypnoGreen.PropertyPath.PropertyPath(new Property("Persons"));
            var data = new
            {
                Persons = new[] { "Michael", "Anders", "Andreas" }
            };

            var value = path.ResolveValue(data, new ReflectionPropertyValueResolver());

            Assert.AreEqual(data.Persons, value);
        }
示例#2
0
        public void ResolveValue_Integer_ReturnsInt()
        {
            var path = new HypnoGreen.PropertyPath.PropertyPath(new Property("Count"));
            var data = new
            {
                Count = 10
            };

            var value = path.ResolveValue <long>(data, new ReflectionPropertyValueResolver());

            Assert.AreEqual(10, value);
        }
示例#3
0
        public object ResolveValue(object data, IPropertyValueResolver propertyValueResolver)
        {
            var propertyValue = _property.ResolveValue(data, propertyValueResolver);

            if (_subPath != null)
            {
                if (propertyValue == null)
                {
                    throw new NullReferenceException($"Intermediate property ${_property} is null. Path: ${ToString()}");
                }

                return(_subPath.ResolveValue(propertyValue, propertyValueResolver));
            }
            return(propertyValue);
        }