private Expression <Func <T, bool> > GetPropertyCondition <T>(WhereQueryProperty property, IEnumerable <PropertyInfo> propertyInfos, ParameterExpression parameterExpression) where T : class { var propertyInfo = propertyInfos.SingleOrDefault(p => p.Name.Equals(property.PropertyName)); if (propertyInfo == null) { return(null); } var propertyType = propertyInfo.PropertyType; if (propertyInfo.PropertyType.ImplementsIEnumerable()) { propertyType = propertyInfo.PropertyType.GetDataTypeFromIEnumerable(); } var data = new ExpressionDataContainer { PropertyInfo = propertyInfo, Parameter = parameterExpression, Operator = property.Operator, ConstantValue = _constantExpressions[propertyType.GetDataType()](property.SearchTerm, propertyType, property.Operator) }; return(GetConditionComparableByProperty <T>(data)); }
private Expression <Func <T, bool> > GetMappingCondition <T>(WhereQueryProperty property, Expression <Func <T, object> > mappingExpression, Type expectedDataType = null) where T : class { var memberExpression = GetMemberExpression(mappingExpression); if (memberExpression == null || (expectedDataType != null && memberExpression.Type != expectedDataType)) { return(null); } var memberType = memberExpression.Type; if (memberType.ImplementsIEnumerable()) { memberType = memberType.GetDataTypeFromIEnumerable(); } var data = new ExpressionDataContainer { Member = memberExpression, Parameter = mappingExpression.Parameters.First(), Operator = property.Operator, ConstantValue = _constantExpressions[memberType.GetDataType()](property.SearchTerm, memberType, property.Operator) }; return(GetConditionComparableByMemberExpression <T>(data)); }
private IEnumerable <Expression <Func <T, bool> > > GetPropertyCondition <T>(WhereQueryProperty property, IEnumerable <PropertyInfo> propertyInfos, ParameterExpression parameterExpression) where T : class { var propertyInfo = propertyInfos.SingleOrDefault(p => p.Name.Equals(property.PropertyName)); if (propertyInfo == null || propertyInfo.GetCustomAttribute <QueryIgnoreAttribute>() != null) { return(Array.Empty <Expression <Func <T, bool> > >()); } var propertyType = propertyInfo.PropertyType; if (propertyInfo.PropertyType.ImplementsIEnumerable()) { propertyType = propertyInfo.PropertyType.GetDataTypeFromIEnumerable(); } var expression = new List <Expression <Func <T, bool> > >(); var searchTermParts = new[] { property.SearchTerm }; if (_options.ContainsSearchSplitBySpace && propertyType == _typeString && property.Operator == CompareOperator.Contains) { searchTermParts = property.SearchTerm.Split(' ').Where(t => !t.IsNullOrEmpty()).ToArray(); } foreach (var searchTermPart in searchTermParts) { var dataType = propertyType.GetDataType(); if (dataType.IsEnum) { dataType = _typeEnum; } var data = new ExpressionDataContainer { PropertyInfo = propertyInfo, Parameter = parameterExpression, Operator = property.Operator, ConstantValue = _constantExpressions[dataType](searchTermPart, propertyType, property.Operator, _options) }; var condition = GetConditionComparableByProperty <T>(data); if (condition != null) { expression.Add(condition); } } return(expression); }
private IList <Expression <Func <T, bool> > > GetMappingCondition <T>(WhereQueryProperty property, Expression <Func <T, object> > mappingExpression, Type expectedDataType = null) where T : class { var memberExpression = GetMemberExpression(mappingExpression); if (memberExpression == null || (expectedDataType != null && memberExpression.Type != expectedDataType)) { return(Array.Empty <Expression <Func <T, bool> > >()); } var memberType = memberExpression.Type; if (memberType.ImplementsIEnumerable()) { memberType = memberType.GetDataTypeFromIEnumerable(); } var expression = new List <Expression <Func <T, bool> > >(); var searchTermParts = new[] { property.SearchTerm }; if (_options.ContainsSearchSplitBySpace && memberType == _typeString && property.Operator == CompareOperator.Contains) { searchTermParts = property.SearchTerm.Split(' ').Where(t => !t.IsNullOrEmpty()).ToArray(); } foreach (var searchTermPart in searchTermParts) { var dataType = memberType.GetDataType(); if (dataType.IsEnum) { dataType = _typeEnum; } var data = new ExpressionDataContainer { Member = memberExpression, Parameter = mappingExpression.Parameters.First(), Operator = property.Operator, ConstantValue = _constantExpressions[dataType](searchTermPart, memberType, property.Operator, _options) }; expression.Add(GetConditionComparableByMemberExpression <T>(data)); } return(expression); }
private Expression <Func <T, bool> > GetConditionComparableByMemberExpression <T>(ExpressionDataContainer data) where T : class { if (data.ConstantValue == null || !_compareOperatorExpressions.ContainsKey(data.Operator)) { return(null); } if (data.Member.Type.IsEnum && _compareOperatorExpressionType.ContainsKey(data.Operator)) { var enumCompareToExpression = Expression.Call(data.Member, data.Member.Type.GetMethod("CompareTo", new[] { data.Member.Type }), Expression.Convert(data.ConstantValue, _typeObject)); var binaryExpression = Expression.MakeBinary(_compareOperatorExpressionType[data.Operator], enumCompareToExpression, _constantExpressionCompareTo); return(Expression.Lambda <Func <T, bool> >(binaryExpression, data.Parameter)); } var expression = _compareOperatorExpressions[data.Operator](data.Member, data.ConstantValue); return(Expression.Lambda <Func <T, bool> >(expression, data.Parameter)); }
private Expression <Func <T, bool> > GetConditionComparableByProperty <T>(ExpressionDataContainer data) where T : class { data.Member = Expression.MakeMemberAccess(data.Parameter, data.PropertyInfo); return(GetConditionComparableByMemberExpression <T>(data)); }
private Expression <Func <T, bool> > GetConditionComparableByMemberExpression <T>(ExpressionDataContainer data) where T : class { if (data.ConstantValue == null || !_compareOperatorExpressions.ContainsKey(data.Operator)) { return(null); } var expression = _compareOperatorExpressions[data.Operator](data.Member, data.ConstantValue); return(Expression.Lambda <Func <T, bool> >(expression, data.Parameter)); }