コード例 #1
0
        private static LinqExpression Evaluate(this CompAttributeExpression compAttributeExpression, System.Linq.Expressions.ParameterExpression arg)
        {
            if (compAttributeExpression == null)
            {
                throw new ArgumentNullException(nameof(compAttributeExpression));
            }

            if (arg == null)
            {
                throw new ArgumentNullException(nameof(arg));
            }

            var resourceAttrParameterExpr        = LinqExpression.Parameter(typeof(RepresentationAttribute), "ra");
            var representationAttributesProperty = LinqExpression.Property(arg, "Attributes");

            var selection    = compAttributeExpression.Path.Evaluate(resourceAttrParameterExpr);
            var equalityExpr = GetComparisonExpression(compAttributeExpression, resourceAttrParameterExpr);
            var equalExpr    = selection;

            if (equalityExpr != null)
            {
                equalExpr = LinqExpression.AndAlso(selection, equalityExpr);
            }

            var andEqual = GetAttributesAny(equalExpr, arg, resourceAttrParameterExpr);

            return(andEqual);
        }
コード例 #2
0
        private static LinqExpression GetComparisonExpression(CompAttributeExpression compAttributeExpression)
        {
            if (compAttributeExpression == null)
            {
                throw new ArgumentNullException(nameof(compAttributeExpression));
            }

            var resourceAttrParameterExpr = LinqExpression.Parameter(typeof(RepresentationAttribute), "r");
            var equalValue = GetComparisonExpression(compAttributeExpression, resourceAttrParameterExpr);

            return(LinqExpression.Lambda <Func <RepresentationAttribute, bool> >(equalValue, resourceAttrParameterExpr));
        }
コード例 #3
0
        private static LinqExpression BuildComparisonExpression(CompAttributeExpression compAttributeExpression, LinqExpression representationAttrExpr)
        {
            var argSchemaAttrValue      = LinqExpression.Parameter(typeof(RepresentationAttributeValue), "rav");
            var propertyValue           = LinqExpression.Property(representationAttrExpr, "Value");
            var propertySchemaAttribute = LinqExpression.Property(representationAttrExpr, "SchemaAttribute");
            var propertySchemaType      = LinqExpression.Property(propertySchemaAttribute, "Type");
            var propertyMultiValued     = LinqExpression.Property(propertySchemaAttribute, "MultiValued");
            var propertyValues          = LinqExpression.Property(representationAttrExpr, "Values");
            var propertySchemaAttrValue = LinqExpression.Property(argSchemaAttrValue, "Value");

            var equality         = LinqExpression.Equal(propertySchemaAttrValue, LinqExpression.Constant(compAttributeExpression.Value));
            var callEqualValue   = LinqExpression.Lambda <Func <RepresentationAttributeValue, bool> >(equality, argSchemaAttrValue);
            var anyExpr          = LinqExpression.Call(typeof(Enumerable), _anyMethodName, new[] { typeof(RepresentationAttributeValue) }, propertyValues, callEqualValue);
            var itemCount        = LinqExpression.Call(typeof(Enumerable), "Count", new[] { typeof(RepresentationAttributeValue) }, propertyValues);
            var moreThanZero     = LinqExpression.GreaterThan(itemCount, LinqExpression.Constant(0));
            var isMultiValued    = LinqExpression.Equal(propertyMultiValued, LinqExpression.Constant(true));
            var isNotMultiValued = LinqExpression.Equal(propertyMultiValued, LinqExpression.Constant(false));

            var equalBoolean        = LinqExpression.Equal(propertySchemaType, LinqExpression.Constant(Common.Constants.SchemaAttributeTypes.Boolean));
            var equalBinary         = LinqExpression.Equal(propertySchemaType, LinqExpression.Constant(Common.Constants.SchemaAttributeTypes.Binary));
            var equalString         = LinqExpression.Equal(propertySchemaType, LinqExpression.Constant(Common.Constants.SchemaAttributeTypes.String));
            var equalDatetime       = LinqExpression.Equal(propertySchemaType, LinqExpression.Constant(Common.Constants.SchemaAttributeTypes.DateTime));
            var equalDecimal        = LinqExpression.Equal(propertySchemaType, LinqExpression.Constant(Common.Constants.SchemaAttributeTypes.Decimal));
            var equalInteger        = LinqExpression.Equal(propertySchemaType, LinqExpression.Constant(Common.Constants.SchemaAttributeTypes.Integer));
            var firstEqualityStr    = LinqExpression.OrElse(equalBoolean, equalBinary);
            var secondEqualityStr   = LinqExpression.OrElse(firstEqualityStr, equalString);
            var firstEqualityFloat  = LinqExpression.OrElse(equalDatetime, equalDecimal);
            var equalityFloat       = LinqExpression.OrElse(firstEqualityFloat, equalInteger);
            var finalEqualityStr    = LinqExpression.OrElse(equalityFloat, secondEqualityStr);
            var containsStr         = LinqExpression.AndAlso(moreThanZero, anyExpr);
            var equalityMultipleStr = LinqExpression.AndAlso(isMultiValued, containsStr);

            var contains           = typeof(string).GetMethod("Contains");
            var containsEqualValue = LinqExpression.Call(propertyValue, contains, LinqExpression.Constant(compAttributeExpression.Value));
            var equalityStr        = LinqExpression.AndAlso(isNotMultiValued, containsEqualValue);

            var checkStrMultiValued = LinqExpression.AndAlso(finalEqualityStr, equalityMultipleStr);
            var checkContainsStr    = LinqExpression.AndAlso(finalEqualityStr, equalityStr);

            return(LinqExpression.OrElse(checkStrMultiValued, checkContainsStr));
        }
コード例 #4
0
        private static LinqExpression GetComparisonExpression(CompAttributeExpression compAttributeExpression, LinqExpression representationAttrExpr)
        {
            if (compAttributeExpression == null)
            {
                throw new ArgumentNullException(nameof(compAttributeExpression));
            }

            if (representationAttrExpr == null)
            {
                throw new ArgumentNullException(nameof(representationAttrExpr));
            }

            var            propertySchemaAttribute = LinqExpression.Property(representationAttrExpr, "SchemaAttribute");
            var            propertySchemaType      = LinqExpression.Property(propertySchemaAttribute, "Type");
            var            propertyValue           = LinqExpression.Property(representationAttrExpr, "Value");
            var            propertyValueNumber     = LinqExpression.Property(representationAttrExpr, "ValueNumber");
            LinqExpression equalValue = null;

            switch (compAttributeExpression.Operator)
            {
            case ComparisonOperators.eq:
                equalValue = LinqExpression.Equal(propertyValue, LinqExpression.Constant(compAttributeExpression.Value));
                break;

            case ComparisonOperators.pr:
                equalValue = LinqExpression.NotEqual(propertyValue, LinqExpression.Constant(null));
                break;

            case ComparisonOperators.co:
                equalValue = BuildComparisonExpression(compAttributeExpression, representationAttrExpr);
                break;

            case ComparisonOperators.gt:
                equalValue = LinqExpression.GreaterThan(propertyValueNumber, LinqExpression.Constant(double.Parse(compAttributeExpression.Value)));
                break;

            case ComparisonOperators.ge:
                equalValue = LinqExpression.GreaterThanOrEqual(propertyValueNumber, LinqExpression.Constant(double.Parse(compAttributeExpression.Value)));
                break;

            case ComparisonOperators.le:
                equalValue = LinqExpression.LessThanOrEqual(propertyValueNumber, LinqExpression.Constant(double.Parse(compAttributeExpression.Value)));
                break;

            case ComparisonOperators.lt:
                equalValue = LinqExpression.LessThan(propertyValueNumber, LinqExpression.Constant(double.Parse(compAttributeExpression.Value)));
                break;

            case ComparisonOperators.sw:
                var startWith = typeof(string).GetMethod("StartsWith");
                equalValue = LinqExpression.Call(propertyValue, startWith, LinqExpression.Constant(compAttributeExpression.Value));
                break;

            case ComparisonOperators.ew:
                var endsWith = typeof(string).GetMethod("EndsWith");
                equalValue = LinqExpression.Call(propertyValue, endsWith, LinqExpression.Constant(compAttributeExpression.Value));
                break;
            }


            return(equalValue);
        }