public static ICollection <SCIMRepresentationAttribute> EvaluateAttributes(this SCIMExpression expression, IQueryable <SCIMRepresentationAttribute> attributes, bool isStrictPath)
        {
            var attr = expression as SCIMAttributeExpression;

            if (attr.SchemaAttribute == null || string.IsNullOrWhiteSpace(attr.SchemaAttribute.Id))
            {
                return(new List <SCIMRepresentationAttribute>());
            }
            else
            {
                var treeNodeParameter  = Expression.Parameter(typeof(SCIMRepresentationAttribute), "tn");
                var anyWhereExpression = expression.EvaluateAttributes(treeNodeParameter);
                var enumarableType     = typeof(Queryable);
                var whereMethod        = enumarableType.GetMethods()
                                         .Where(m => m.Name == "Where" && m.IsGenericMethodDefinition)
                                         .Where(m => m.GetParameters().Count() == 2).First().MakeGenericMethod(typeof(SCIMRepresentationAttribute));
                var equalLambda            = Expression.Lambda <Func <SCIMRepresentationAttribute, bool> >(anyWhereExpression, treeNodeParameter);
                var whereExpr              = Expression.Call(whereMethod, Expression.Constant(attributes), equalLambda);
                var finalSelectArg         = Expression.Parameter(typeof(IQueryable <SCIMRepresentationAttribute>), "f");
                var finalSelectRequestBody = Expression.Lambda(whereExpr, new ParameterExpression[] { finalSelectArg });
                var result   = (IQueryable <SCIMRepresentationAttribute>)finalSelectRequestBody.Compile().DynamicInvoke(attributes);
                var fullPath = attr.GetFullPath();
                var res      = SCIMRepresentation.BuildFlatAttributes(result.ToList());
                return(res.Where((a) => a != null && (isStrictPath ? fullPath == a.FullPath : fullPath.StartsWith(a.FullPath) || a.FullPath.StartsWith(fullPath))).ToList());
            }
        }
        public static Expression Evaluate(this SCIMExpression expression, ParameterExpression parameterExpression)
        {
            var compAttrExpression = expression as SCIMComparisonExpression;
            var attrExpression     = expression as SCIMAttributeExpression;
            var logicalExpression  = expression as SCIMLogicalExpression;
            var notExpression      = expression as SCIMNotExpression;
            var presentExpression  = expression as SCIMPresentExpression;

            if (compAttrExpression != null)
            {
                return(compAttrExpression.Evaluate(parameterExpression));
            }

            if (attrExpression != null)
            {
                return(attrExpression.Evaluate(parameterExpression));
            }

            if (logicalExpression != null)
            {
                return(logicalExpression.Evaluate(parameterExpression));
            }

            if (notExpression != null)
            {
                return(notExpression.Evaluate(parameterExpression));
            }

            if (presentExpression != null)
            {
                return(presentExpression.Evaluate(parameterExpression));
            }

            return(null);
        }
        public static LambdaExpression Evaluate(this SCIMExpression expression, IQueryable <SCIMRepresentation> representations)
        {
            var representationParameter = Expression.Parameter(typeof(SCIMRepresentation), "rp");
            var anyLambdaExpression     = expression.Evaluate(representationParameter);
            var enumarableType          = typeof(Queryable);
            var whereMethod             = enumarableType.GetMethods()
                                          .Where(m => m.Name == "Where" && m.IsGenericMethodDefinition)
                                          .Where(m => m.GetParameters().Count() == 2).First().MakeGenericMethod(typeof(SCIMRepresentation));
            var equalLambda            = Expression.Lambda <Func <SCIMRepresentation, bool> >(anyLambdaExpression, representationParameter);
            var whereExpr              = Expression.Call(whereMethod, Expression.Constant(representations), equalLambda);
            var finalSelectArg         = Expression.Parameter(typeof(IQueryable <SCIMRepresentation>), "f");
            var finalSelectRequestBody = Expression.Lambda(whereExpr, new ParameterExpression[] { finalSelectArg });

            return(finalSelectRequestBody);
        }
        public static LambdaExpression EvaluateOrderBy(this SCIMExpression expression, IQueryable <SCIMRepresentation> representations, SearchSCIMRepresentationOrders order)
        {
            var attrExpression = expression as SCIMAttributeExpression;

            if (attrExpression == null)
            {
                return(null);
            }

            var result = EvaluateOrderByMetadata(attrExpression, representations, order);

            if (result == null)
            {
                result = EvaluateOrderByProperty(attrExpression, representations, order);
            }

            return(result);
        }
 public SCIMLogicalExpression(SCIMLogicalOperators logicalOperator, SCIMExpression leftExpression, SCIMExpression rightExpression)
 {
     LogicalOperator = logicalOperator;
     LeftExpression  = leftExpression;
     RightExpression = rightExpression;
 }