CreateFieldValueExpression() public method

Creates a FieldValueExpression from a MethodCallExpression.
public CreateFieldValueExpression ( MethodCallExpression expression, BindingSignatureSupport reportedSignatureSupport ) : FieldValueExpression
expression System.Linq.Expressions.MethodCallExpression The expression.
reportedSignatureSupport BindingSignatureSupport A component outlining the supported expression structure of this provider.
return Rebel.Framework.Linq.CriteriaGeneration.Expressions.FieldValueExpression
コード例 #1
0
        /// <summary>
        /// Converts a <see cref="BinaryExpression"/> to a field predicate expression, if supported and convertible.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="structureBinder">The structure binder.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Expression ConvertToFieldPredicate(BinaryExpression expression, AbstractQueryStructureBinder structureBinder)
        {
            if (IsConvertibleBinary(expression, structureBinder))
            {
                var left = expression.Left;

                // Check if the left had side is a Unary wrapping a DynamicMemberMetadata call just to get the type right
                var unaryLeft = left as UnaryExpression;
                if (unaryLeft != null)
                {
                    var methodLeft = unaryLeft.Operand as MethodCallExpression;
                    if (methodLeft != null && methodLeft.Method == DynamicMemberMetadata.GetMemberMethod)
                    {
                        left = methodLeft;
                    }
                }

                // First assume that the right hand side of the binary is a constant
                ConstantExpression right = expression.Right as ConstantExpression;

                // If it's not, it might be a unary (e.g. "convert value to object" if it's from DynamicMemberMetadata)
                if (right == null)
                {
                    var unary = expression.Right as UnaryExpression;
                    if (unary != null)
                    {
                        // If it was a unary, ignore the operator and just go for the operand (the value)
                        right = unary.Operand as ConstantExpression;
                    }
                }

                BindingSignatureSupport leftBindingSignatureSupport = GetBindingSupport(left, structureBinder);

                // Update the ValuePredicateType based on the expression which might reference an operator or a NodeType of NotEqual etc.
                UpdateValuePredicateType(leftBindingSignatureSupport, expression);

                switch (leftBindingSignatureSupport.SignatureSupportType)
                {
                    case SignatureSupportType.SupportedAsFieldName:
                        var selectorExpression = GetFieldSelector(left, structureBinder, leftBindingSignatureSupport);
                        return new FieldPredicateExpression(selectorExpression, new FieldValueExpression(leftBindingSignatureSupport.NodeType, right.Value));
                    case SignatureSupportType.SupportedAsFieldValue:
                        var methodCallExpression = ((MethodCallExpression)left);
                        if (ExpressionHelper.IsMethod(left))
                        {
                            var fieldValueExpression = structureBinder
                                .CreateFieldValueExpression(methodCallExpression, leftBindingSignatureSupport);

                            var objectOfMethod = methodCallExpression.Object;
                            var bindingSupportForMethodObject = GetBindingSupport(objectOfMethod, structureBinder);
                            var fieldSelector = GetFieldSelector(objectOfMethod, structureBinder, bindingSupportForMethodObject);

                            return new FieldPredicateExpression(fieldSelector, fieldValueExpression);
                        }
                        break;
                    case SignatureSupportType.SupportedAsSchemaAlias:
                        var schemaSelectorExpression = GetSchemaSelector(left, structureBinder, leftBindingSignatureSupport);
                        return
                            new SchemaPredicateExpression(
                                new SchemaSelectorExpression(schemaSelectorExpression.Name),
                                new SchemaValueExpression(leftBindingSignatureSupport.NodeType, right.Value));
                }
            }

            return expression;
        }