Beispiel #1
0
        public void FindsCorrectExpressionWithInheritance()
        {
            var collection = new QueryFilterExpressionCollection();

            collection.SetExpression <Parent>((x, y) => x != y);
            var property = CreatePropertyInfo <Child>();

            var result = collection.GetQueryFilterExpression(property);

            AssertExpressionEqual <Child>((x, y) => x != y, result);
        }
Beispiel #2
0
        public void WorksWithMethodCalls()
        {
            var collection = new QueryFilterExpressionCollection();

            collection.SetExpression <Child>((x, y) => x.StringEquals(y.ToString()));
            var property = CreatePropertyInfo <Child>();

            var result = collection.GetQueryFilterExpression(property);

            AssertExpressionEqual <Child>((x, y) => x.StringEquals(y.ToString()), result);
        }
Beispiel #3
0
        public void HasDefaultExpression()
        {
            var collection     = new QueryFilterExpressionCollection();
            var childProperty  = CreatePropertyInfo <Child>();
            var parentProperty = CreatePropertyInfo <Parent>();

            var childResult  = collection.GetQueryFilterExpression(childProperty);
            var parentResult = collection.GetQueryFilterExpression(parentProperty);

            AssertExpressionEqual <Child>((x, y) => x == y, childResult);
            AssertExpressionEqual <Parent>((x, y) => x == y, parentResult);
        }
Beispiel #4
0
        public void SetOverridesOldValue()
        {
            var collection = new QueryFilterExpressionCollection();
            var property   = CreatePropertyInfo <Child>();

            collection.SetExpression <Child>((x, y) => x.GetHashCode() == y.GetHashCode());
            var result = collection.GetQueryFilterExpression(property);

            AssertExpressionEqual <Child>((x, y) => x.GetHashCode() == y.GetHashCode(), result);

            collection.SetExpression <Child>((x, y) => x != y);
            result = collection.GetQueryFilterExpression(property);
            AssertExpressionEqual <Child>((x, y) => x != y, result);
        }
Beispiel #5
0
        public void FindsRealTypeFirst()
        {
            var collection = new QueryFilterExpressionCollection();

            collection.SetExpression <Parent>((x, y) => x != y);
            collection.SetExpression <Child>((x, y) => x.GetHashCode() == y.GetHashCode());
            var childProperty  = CreatePropertyInfo <Child>();
            var parentProperty = CreatePropertyInfo <Parent>();

            var childResult  = collection.GetQueryFilterExpression(childProperty);
            var parentResult = collection.GetQueryFilterExpression(parentProperty);

            AssertExpressionEqual <Child>((x, y) => x.GetHashCode() == y.GetHashCode(), childResult);
            AssertExpressionEqual <Parent>((x, y) => x != y, parentResult);
        }
Beispiel #6
0
        public static Expression SelectPropertyValue(Type type, string property, string value, QueryFilterExpressionCollection queryFilter)
        {
            var valueType          = GetPropertyType(type, property);
            var parsedValue        = TryConvert(value, valueType);
            var param              = Expression.Parameter(type, "i");
            var propertyExpression = Expression.Property(param, property);

            var expression = queryFilter.GetQueryFilterExpression(type.GetProperty(property));

            return(typeof(Lambda)
                   .GetMethod(nameof(Convert), BindingFlags.Static | BindingFlags.NonPublic)
                   .MakeGenericMethod(valueType, type)
                   .Invoke(null, new[] { expression, parsedValue, propertyExpression, param })
                   as Expression);
        }
Beispiel #7
0
        public static Expression SelectPropertyValue(Type type, string property, List <string> values, QueryFilterExpressionCollection queryFilter)
        {
            var valueType             = GetPropertyType(type, property);
            var parsedValuesAsObjects = values.Select(v => TryConvert(v, valueType)).ToList();

            var parsedValues = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(valueType));

            foreach (var parsedValueAsObject in parsedValuesAsObjects)
            {
                parsedValues.Add(parsedValueAsObject);
            }

            var        param = Expression.Parameter(type, "i");
            Expression propertyExpression = param;

            foreach (var member in property.Split('.'))
            {
                propertyExpression = Expression.PropertyOrField(propertyExpression, member);
            }

            var expression = queryFilter.GetQueryFilterExpression(GetPropertyInfo(type, property));

            return(typeof(Lambda)
                   .GetMethod(nameof(Convert), BindingFlags.Static | BindingFlags.NonPublic)
                   .MakeGenericMethod(valueType, type)
                   .Invoke(null, new object[] { expression, parsedValues, propertyExpression, param })
                   as Expression);
        }