private static bool IsCommonAttribute(SCIMAttributeExpression scimAttributeExpression) { return(MAPPING_PATH_TO_PROPERTYNAMES.ContainsKey(scimAttributeExpression.GetFullPath())); }
private static Expression Evaluate(this SCIMAttributeExpression attributeExpression, ParameterExpression parameterExpression, Func <ParameterExpression, Expression> callback = null) { var originalParameterExpression = parameterExpression; if (parameterExpression.Type == typeof(SCIMRepresentation)) { parameterExpression = Expression.Parameter(typeof(SCIMRepresentationAttribute), "ra"); } var schemaAttributeProperty = Expression.Property(parameterExpression, "SchemaAttribute"); var valuesProperty = Expression.Property(parameterExpression, "Values"); var nameProperty = Expression.Property(schemaAttributeProperty, "Name"); var notEqual = Expression.NotEqual(schemaAttributeProperty, Expression.Constant(null)); var equal = Expression.Equal(nameProperty, Expression.Constant(attributeExpression.Name)); var result = Expression.AndAlso(notEqual, equal); var complexAttributeExpression = attributeExpression as SCIMComplexAttributeExpression; if (complexAttributeExpression != null) { if (originalParameterExpression.Type == typeof(SCIMRepresentation)) { var lambdaExpression = complexAttributeExpression.GroupingFilter.Evaluate(parameterExpression); result = Expression.AndAlso(result, lambdaExpression); } else { var logicalExpr = complexAttributeExpression.GroupingFilter as SCIMLogicalExpression; if (logicalExpr != null) { var subParameter = Expression.Parameter(typeof(SCIMRepresentationAttribute), Guid.NewGuid().ToString("N")); var leftExpr = logicalExpr.LeftExpression.Evaluate(subParameter); var rightExpr = logicalExpr.RightExpression.Evaluate(subParameter); var anyLeftLambda = Expression.Lambda <Func <SCIMRepresentationAttribute, bool> >(leftExpr, subParameter); var anyRightLambda = Expression.Lambda <Func <SCIMRepresentationAttribute, bool> >(rightExpr, subParameter); var anyLeftCall = Expression.Call(typeof(Enumerable), "Any", new[] { typeof(SCIMRepresentationAttribute) }, valuesProperty, anyLeftLambda); var anyRightCall = Expression.Call(typeof(Enumerable), "Any", new[] { typeof(SCIMRepresentationAttribute) }, valuesProperty, anyRightLambda); if (logicalExpr.LogicalOperator == SCIMLogicalOperators.AND) { result = Expression.AndAlso(result, Expression.AndAlso(anyLeftCall, anyRightCall)); } else { result = Expression.AndAlso(result, Expression.Or(anyLeftCall, anyRightCall)); } } else { var subParameter = Expression.Parameter(typeof(SCIMRepresentationAttribute), Guid.NewGuid().ToString("N")); var lambdaExpression = complexAttributeExpression.GroupingFilter.Evaluate(subParameter); var anyLambda = Expression.Lambda <Func <SCIMRepresentationAttribute, bool> >(lambdaExpression, subParameter); var anyCall = Expression.Call(typeof(Enumerable), "Any", new[] { typeof(SCIMRepresentationAttribute) }, valuesProperty, anyLambda); result = Expression.AndAlso(result, anyCall); } } } if (attributeExpression.Child != null) { var firstSubParameter = Expression.Parameter(typeof(SCIMRepresentationAttribute), Guid.NewGuid().ToString("N")); var secondSubParameter = Expression.Parameter(typeof(SCIMRepresentationAttribute), Guid.NewGuid().ToString("N")); var lambdaExpression = attributeExpression.Child.Evaluate(firstSubParameter, callback); var anyLambda = Expression.Lambda <Func <SCIMRepresentationAttribute, bool> >(lambdaExpression, firstSubParameter); var anyCall = Expression.Call(typeof(Enumerable), "Any", new[] { typeof(SCIMRepresentationAttribute) }, valuesProperty, anyLambda); result = Expression.AndAlso(result, anyCall); } if (callback != null && attributeExpression.Child == null) { result = Expression.AndAlso(result, callback(parameterExpression)); } if (originalParameterExpression.Type == typeof(SCIMRepresentation)) { var attributesProperty = Expression.Property(originalParameterExpression, "Attributes"); var anyLambda = Expression.Lambda <Func <SCIMRepresentationAttribute, bool> >(result, parameterExpression); return(Expression.Call(typeof(Enumerable), "Any", new[] { typeof(SCIMRepresentationAttribute) }, attributesProperty, anyLambda)); } return(result); }
public SCIMComparisonExpression(SCIMComparisonOperators comparisonOperator, SCIMAttributeExpression leftExpression, string value) { ComparisonOperator = comparisonOperator; LeftExpression = leftExpression; Value = value; }