Provides metadata to an expression tree binder in order to identify which types of methods or members are denoted by which ValuePredicateType by returning a SignatureSupportType.
        /// <summary>
        /// Creates the field selector.
        /// </summary>
        /// <param name="fieldame">The fieldame.</param>
        /// <param name="innerFieldName">Name of the inner field.</param>
        /// <param name="reportedSignatureSupport">The reported signature support.</param>
        /// <returns></returns>
        public virtual FieldSelectorExpression CreateFieldSelector(string fieldame, string innerFieldName, BindingSignatureSupport reportedSignatureSupport)
        {
            if(!string.IsNullOrWhiteSpace(innerFieldName))
                return  new FieldSelectorExpression(innerFieldName);

            return new FieldSelectorExpression(fieldame);
        }
        /// <summary>
        /// Creates a <see cref="FieldSelectorExpression"/> from a <see cref="MethodCallExpression"/>.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override FieldSelectorExpression CreateFieldSelector(MethodCallExpression expression, BindingSignatureSupport reportedSignatureSupport)
        {
            switch (expression.Method.Name)
            {
                case "Field":
                    // This is an extension method for the RenderViewModel so the first argument is the extended object
                    return new FieldSelectorExpression(((ConstantExpression)expression.Arguments[1]).Value.ToString());
                case "StringField":
                    // This is an extension method for the RenderViewModel so the first argument is the extended object
                    return new FieldSelectorExpression(((ConstantExpression)expression.Arguments[1]).Value.ToString());
                case "NumberField":
                    // This is an extension method for the RenderViewModel so the first argument is the extended object
                    return new FieldSelectorExpression(((ConstantExpression)expression.Arguments[1]).Value.ToString());
                case "BooleanField":
                    // This is an extension method for the RenderViewModel so the first argument is the extended object
                    return new FieldSelectorExpression(((ConstantExpression)expression.Arguments[1]).Value.ToString());
                case "get_Item":
                    // This is the default accessor of a Dictionary, so check if the parent object is supported too
                    if (ExpressionHelper.IsMember(expression.Object) && IsSupportedMember(expression.Object as MemberExpression).SignatureSupportType != SignatureSupportType.NotSupported)
                        return new FieldSelectorExpression(((ConstantExpression) expression.Arguments[0]).Value.ToString());
                    break;
            }

            return base.CreateFieldSelector(expression, reportedSignatureSupport);
        }
        /// <summary>
        /// Creates a <see cref="FieldSelectorExpression"/> from a <see cref="MemberExpression"/>.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public virtual FieldSelectorExpression CreateFieldSelector(MemberExpression expression, BindingSignatureSupport reportedSignatureSupport)
        {
            var memberParent = expression.Expression as MemberExpression;
            if (memberParent != null)
                return CreateFieldSelector(memberParent.Member.Name, expression.Member.Name, reportedSignatureSupport);

            return CreateFieldSelector(expression.Member.Name, null, reportedSignatureSupport);
        }
 /// <summary>
 /// Creates a field selector.
 /// </summary>
 /// <param name="fieldName">Name of the field.</param>
 /// <param name="innerFieldName">Name of the inner field.</param>
 /// <param name="reportedSignatureSupport">The reported signature support.</param>
 /// <returns></returns>
 public override FieldSelectorExpression CreateFieldSelector(string fieldName, string innerFieldName, BindingSignatureSupport reportedSignatureSupport)
 {
     switch (fieldName)
     {
         case "Name":
             return new FieldSelectorExpression("system-internal-node-name", fieldName);
         case "UrlName":
             return new FieldSelectorExpression("system-internal-node-name", fieldName);
         case "Template":
         case "TemplateId":
         case "CurrentTemplate":
             return new FieldSelectorExpression("system-internal-selected-template", "TemplateId");
         default:
             return base.CreateFieldSelector(fieldName, innerFieldName, reportedSignatureSupport);
     }
 }
        /// <summary>
        /// Creates a <see cref="FieldSelectorExpression"/> from a <see cref="MethodCallExpression"/>.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override FieldSelectorExpression CreateFieldSelector(MethodCallExpression expression, BindingSignatureSupport reportedSignatureSupport)
        {
            switch (expression.Method.Name)
            {
                case "Attribute":
                    // This is an extension method for the Persistence model so the first argument is the extended object
                    
                    if (expression.Arguments.Count == 3)
                    {
                        //if there are 3 arguments, then we are selecting a field by name with a value key
                        return new FieldSelectorExpression(
                            ((ConstantExpression) expression.Arguments[1]).Value.ToString(),
                            ((ConstantExpression) expression.Arguments[2]).Value.ToString());
                    }
                    if (expression.Arguments.Count == 2)
                    {                        
                        //if there are 2 arguments, then we are selecting a field only by name regardless of the value key
                        return new FieldSelectorExpression(((ConstantExpression)expression.Arguments[1]).Value.ToString());    
                    }
                    break;
                case "get_Item":
                    // This is the default accessor of a Dictionary, so check if the parent object is supported too
                    if (ExpressionHelper.IsMember(expression.Object) && IsSupportedMember(expression.Object as MemberExpression).SignatureSupportType != SignatureSupportType.NotSupported)
                        return new FieldSelectorExpression(((ConstantExpression)expression.Arguments[0]).Value.ToString());

                    // There are two dictionaries on this model, the TypedAttributeCollection and its child TypedAttributeValueCollection.
                    // Make sure we're getting the field name from the TypedAttributeCollection indexer. To do this, access the MemberExpression
                    // "one up the chain" and recurse back into this method.
                    if (ExpressionHelper.IsMember(expression.Object) && ExpressionHelper.IsMethod(((MemberExpression)expression.Object).Expression))
                        return CreateFieldSelector(((MemberExpression)expression.Object).Expression as MethodCallExpression, reportedSignatureSupport);

                    break;
            }

            return base.CreateFieldSelector(expression, reportedSignatureSupport);
        }
 private static SchemaSelectorExpression GetSchemaSelector(Expression left, AbstractQueryStructureBinder structureBinder, BindingSignatureSupport bindingSignatureSupport)
 {
     switch (bindingSignatureSupport.SignatureSupportType)
     {
         case SignatureSupportType.SupportedAsSchemaAlias:
             if (ExpressionHelper.IsMember(left))
                 return structureBinder.CreateSchemaSelector(left as MemberExpression, bindingSignatureSupport);
             else if (ExpressionHelper.IsMethod(left))
                 return structureBinder.CreateSchemaSelector(left as MethodCallExpression, bindingSignatureSupport);
             break;
     }
     return null;
 }
        private static void UpdateValuePredicateType(BindingSignatureSupport signatureSupport, BinaryExpression binaryExpression)
        {
            // Only modify the ValuePredicateType if it already is "Equals" or "Empty". This is pending a refactor
            // of BindingSignatureSupport to include a negation property and the removal of NotEquals

            if (signatureSupport.NodeType != ValuePredicateType.Equal && signatureSupport.NodeType != ValuePredicateType.Empty) return;

            // First check the NodeType. Binaries joined with "!= true" will have a NodeType of NotEqual
            switch (binaryExpression.NodeType)
            {
                case ExpressionType.Equal:
                    signatureSupport.NodeType = ValuePredicateType.Equal;
                    break;
                case ExpressionType.NotEqual:
                    signatureSupport.NodeType = ValuePredicateType.NotEqual;
                    break;
                case ExpressionType.GreaterThan:
                    signatureSupport.NodeType = ValuePredicateType.GreaterThan;
                    break;
                case ExpressionType.GreaterThanOrEqual:
                    signatureSupport.NodeType = ValuePredicateType.GreaterThanOrEqual;
                    break;
                case ExpressionType.LessThan:
                    signatureSupport.NodeType = ValuePredicateType.LessThan;
                    break;
                case ExpressionType.LessThanOrEqual:
                    signatureSupport.NodeType = ValuePredicateType.LessThanOrEqual;
                    break;
            }

            // Then check the Method, which might be an operator
            if (binaryExpression.Method != null)
                switch (binaryExpression.Method.Name)
                {
                    case "op_Inequality":
                        signatureSupport.NodeType = ValuePredicateType.NotEqual;
                        break;
                }
        }
        /// <summary>
        /// Creates a <see cref="FieldSelectorExpression"/> from a <see cref="MethodCallExpression"/>.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override FieldSelectorExpression CreateFieldSelector(MethodCallExpression expression, BindingSignatureSupport reportedSignatureSupport)
        {
            // If the method has parameters, look at the attributes of each parameter to see if they map to a field name
            string foundField = null;
            string foundSubField = null;
            var parameterInfos = expression.Method.GetParameters();
            for (int index   = 0; index < parameterInfos.Length; index++)
            {
                if (foundField == null)
                {
                    var parameterInfo = parameterInfos[index];
                    var attribs =
                        parameterInfo.GetCustomAttributes(typeof (MapsToAliasForQueryingAttribute), true).OfType
                            <MapsToAliasForQueryingAttribute>()
                            .FirstOrDefault();
                    if (attribs != null)
                    {
                        var arg = expression.Arguments.ToArray()[index] as ConstantExpression;
                        if (arg != null)
                        {
                            foundField = arg.Value.ToString();
                        }
                    }
                }
                if (foundSubField == null)
                {
                    var parameterInfo = parameterInfos[index];
                    var attribs =
                        parameterInfo.GetCustomAttributes(typeof(MapsToInnerAliasForQueryingAttribute), true).OfType
                            <MapsToInnerAliasForQueryingAttribute>()
                            .FirstOrDefault();
                    if (attribs != null)
                    {
                        var arg = expression.Arguments.ToArray()[index] as ConstantExpression;
                        if (arg != null)
                        {
                            foundSubField = arg.Value.ToString();
                        }
                    }
                }
            }

            if (foundField != null)
            {
                if (foundSubField != null)
                {
                    return new FieldSelectorExpression(foundField, foundSubField);
                }
                return new FieldSelectorExpression(foundField);
            }
            
            switch (expression.Method.Name)
            {
                case "Field":
                    // This is an extension method for the RenderViewModel so the first argument is the extended object
                    return new FieldSelectorExpression(((ConstantExpression)expression.Arguments[1]).Value.ToString());
                case "get_Item":
                    // This is the default accessor of a Dictionary, so check if the parent object is supported too
                    // and also allow for dictionary-of-dictionary

                    // First check explicit mappings e.g. TypedAttribute[index].Values[subindex]
                    var containerExpr = expression.Object as MemberExpression;

                    if (expression.Method.GetCustomAttributes(typeof(MapsToInnerAliasForQueryingAttribute), true).Any())
                    {
                        var innerFieldExpression = expression.Arguments[0] as ConstantExpression;
                        if (innerFieldExpression != null)
                        {
                            foundSubField = innerFieldExpression.Value.ToString();
                        }
                    }

                    if (containerExpr != null)
                    {
                        var callExpression = containerExpr.Expression as MethodCallExpression;
                        if (callExpression != null)
                        {
                            if (containerExpr.Member.GetCustomAttributes(typeof(MapsToInnerAliasForQueryingAttribute), true).Any())
                            {
                                var innerFieldExpression = callExpression.Arguments[0] as ConstantExpression;
                                if (innerFieldExpression != null)
                                {
                                    foundField = innerFieldExpression.Value.ToString();
                                }
                            }
                        }
                    }
                    if (foundField != null)
                    {
                        if (foundSubField != null)
                        {
                            return new FieldSelectorExpression(foundField, foundSubField);
                        }
                        return new FieldSelectorExpression(foundField);
                    }

                    if (ExpressionHelper.IsMember(expression.Object) && IsSupportedMember(containerExpr).SignatureSupportType != SignatureSupportType.NotSupported)
                        return new FieldSelectorExpression(((ConstantExpression) expression.Arguments[0]).Value.ToString());
                    break;
            }

            // Add support for dynamic expressions using an intermediary set of "fake" methods on DynamicMemberMetadata
            if (expression.Method == DynamicMemberMetadata.GetMemberMethod)
            {
                // The first argument is the field name
                return CreateFieldSelector(((ConstantExpression)expression.Arguments[0]).Value.ToString(), null, reportedSignatureSupport);
            }

            return base.CreateFieldSelector(expression, reportedSignatureSupport);
        }
 /// <summary>
 /// Creates a <see cref="FieldValueExpression"/> from a <see cref="MethodCallExpression"/>.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
 /// <returns></returns>
 /// <remarks></remarks>
 public virtual FieldValueExpression CreateFieldValueExpression(MethodCallExpression expression, BindingSignatureSupport reportedSignatureSupport)
 {
     return(new FieldValueExpression(reportedSignatureSupport.NodeType, ExpressionHelper.GetFirstValueFromArguments(expression.Arguments)));
 }
 public virtual SchemaSelectorExpression CreateSchemaSelector(MemberExpression expression, BindingSignatureSupport reportedSignatureSupport)
 {
     return(new SchemaSelectorExpression(expression.Member.Name));
 }
        /// <summary>
        /// Creates the field selector.
        /// </summary>
        /// <param name="fieldame">The fieldame.</param>
        /// <param name="innerFieldName">Name of the inner field.</param>
        /// <param name="reportedSignatureSupport">The reported signature support.</param>
        /// <returns></returns>
        public virtual FieldSelectorExpression CreateFieldSelector(string fieldame, string innerFieldName, BindingSignatureSupport reportedSignatureSupport)
        {
            if (!string.IsNullOrWhiteSpace(innerFieldName))
            {
                return(new FieldSelectorExpression(innerFieldName));
            }

            return(new FieldSelectorExpression(fieldame));
        }
 /// <summary>
 /// Creates a <see cref="FieldSelectorExpression"/> from a <see cref="MethodCallExpression"/>.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
 /// <returns></returns>
 /// <remarks></remarks>
 public virtual FieldSelectorExpression CreateFieldSelector(MethodCallExpression expression, BindingSignatureSupport reportedSignatureSupport)
 {
     return CreateFieldSelector(expression.Method.Name, null, reportedSignatureSupport);
 }
 /// <summary>
 /// Creates a <see cref="FieldSelectorExpression"/> from a <see cref="MethodCallExpression"/>.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
 /// <returns></returns>
 /// <remarks></remarks>
 public virtual FieldSelectorExpression CreateFieldSelector(MethodCallExpression expression, BindingSignatureSupport reportedSignatureSupport)
 {
     return(CreateFieldSelector(expression.Method.Name, null, reportedSignatureSupport));
 }
 /// <summary>
 /// Creates a <see cref="FieldValueExpression"/> from a <see cref="MethodCallExpression"/>.
 /// </summary>
 /// <param name="expression">The expression.</param>
 /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
 /// <returns></returns>
 /// <remarks></remarks>
 public virtual FieldValueExpression CreateFieldValueExpression(MethodCallExpression expression, BindingSignatureSupport reportedSignatureSupport)
 {
     return new FieldValueExpression(reportedSignatureSupport.NodeType, ExpressionHelper.GetFirstValueFromArguments(expression.Arguments));
 }
 public virtual SchemaSelectorExpression CreateSchemaSelector(MemberExpression expression, BindingSignatureSupport reportedSignatureSupport)
 {
     return new SchemaSelectorExpression(expression.Member.Name);
 }
 /// <summary>
 /// Gets a <see cref="FieldSelectorExpression"/> from an expression it the <paramref name="bindingSignatureSupport"/> identifies it as supported.
 /// </summary>
 /// <param name="left">The left.</param>
 /// <param name="structureBinder">The structure binder.</param>
 /// <param name="bindingSignatureSupport">The binding signature support.</param>
 /// <returns></returns>
 /// <remarks></remarks>
 public static FieldSelectorExpression GetFieldSelector(Expression left, AbstractQueryStructureBinder structureBinder, BindingSignatureSupport bindingSignatureSupport)
 {
     switch (bindingSignatureSupport.SignatureSupportType)
     {
         case SignatureSupportType.SupportedAsFieldName:
             if (ExpressionHelper.IsMember(left))
                 return structureBinder.CreateFieldSelector(left as MemberExpression, bindingSignatureSupport);
             else if (ExpressionHelper.IsMethod(left))
                 return structureBinder.CreateFieldSelector(left as MethodCallExpression, bindingSignatureSupport);
             break;
     }
     return null;
 }
Exemple #17
0
        /// <summary>
        /// Creates a <see cref="FieldSelectorExpression"/> from a <see cref="MethodCallExpression"/>.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override FieldSelectorExpression CreateFieldSelector(MethodCallExpression expression, BindingSignatureSupport reportedSignatureSupport)
        {
            // If the method has parameters, look at the attributes of each parameter to see if they map to a field name
            string foundField     = null;
            string foundSubField  = null;
            var    parameterInfos = expression.Method.GetParameters();

            for (int index = 0; index < parameterInfos.Length; index++)
            {
                if (foundField == null)
                {
                    var parameterInfo = parameterInfos[index];
                    var attribs       =
                        parameterInfo.GetCustomAttributes(typeof(MapsToAliasForQueryingAttribute), true).OfType
                        <MapsToAliasForQueryingAttribute>()
                        .FirstOrDefault();
                    if (attribs != null)
                    {
                        var arg = expression.Arguments.ToArray()[index] as ConstantExpression;
                        if (arg != null)
                        {
                            foundField = arg.Value.ToString();
                        }
                    }
                }
                if (foundSubField == null)
                {
                    var parameterInfo = parameterInfos[index];
                    var attribs       =
                        parameterInfo.GetCustomAttributes(typeof(MapsToInnerAliasForQueryingAttribute), true).OfType
                        <MapsToInnerAliasForQueryingAttribute>()
                        .FirstOrDefault();
                    if (attribs != null)
                    {
                        var arg = expression.Arguments.ToArray()[index] as ConstantExpression;
                        if (arg != null)
                        {
                            foundSubField = arg.Value.ToString();
                        }
                    }
                }
            }

            if (foundField != null)
            {
                if (foundSubField != null)
                {
                    return(new FieldSelectorExpression(foundField, foundSubField));
                }
                return(new FieldSelectorExpression(foundField));
            }

            switch (expression.Method.Name)
            {
            case "Field":
                // This is an extension method for the RenderViewModel so the first argument is the extended object
                return(new FieldSelectorExpression(((ConstantExpression)expression.Arguments[1]).Value.ToString()));

            case "get_Item":
                // This is the default accessor of a Dictionary, so check if the parent object is supported too
                // and also allow for dictionary-of-dictionary

                // First check explicit mappings e.g. TypedAttribute[index].Values[subindex]
                var containerExpr = expression.Object as MemberExpression;

                if (expression.Method.GetCustomAttributes(typeof(MapsToInnerAliasForQueryingAttribute), true).Any())
                {
                    var innerFieldExpression = expression.Arguments[0] as ConstantExpression;
                    if (innerFieldExpression != null)
                    {
                        foundSubField = innerFieldExpression.Value.ToString();
                    }
                }

                if (containerExpr != null)
                {
                    var callExpression = containerExpr.Expression as MethodCallExpression;
                    if (callExpression != null)
                    {
                        if (containerExpr.Member.GetCustomAttributes(typeof(MapsToInnerAliasForQueryingAttribute), true).Any())
                        {
                            var innerFieldExpression = callExpression.Arguments[0] as ConstantExpression;
                            if (innerFieldExpression != null)
                            {
                                foundField = innerFieldExpression.Value.ToString();
                            }
                        }
                    }
                }
                if (foundField != null)
                {
                    if (foundSubField != null)
                    {
                        return(new FieldSelectorExpression(foundField, foundSubField));
                    }
                    return(new FieldSelectorExpression(foundField));
                }

                if (ExpressionHelper.IsMember(expression.Object) && IsSupportedMember(containerExpr).SignatureSupportType != SignatureSupportType.NotSupported)
                {
                    return(new FieldSelectorExpression(((ConstantExpression)expression.Arguments[0]).Value.ToString()));
                }
                break;
            }

            // Add support for dynamic expressions using an intermediary set of "fake" methods on DynamicMemberMetadata
            if (expression.Method == DynamicMemberMetadata.GetMemberMethod)
            {
                // The first argument is the field name
                return(CreateFieldSelector(((ConstantExpression)expression.Arguments[0]).Value.ToString(), null, reportedSignatureSupport));
            }

            return(base.CreateFieldSelector(expression, reportedSignatureSupport));
        }
        /// <summary>
        /// Creates a <see cref="FieldSelectorExpression"/> from a <see cref="MemberExpression"/>.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="reportedSignatureSupport">A component outlining the supported expression structure of this provider.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public virtual FieldSelectorExpression CreateFieldSelector(MemberExpression expression, BindingSignatureSupport reportedSignatureSupport)
        {
            var memberParent = expression.Expression as MemberExpression;

            if (memberParent != null)
            {
                return(CreateFieldSelector(memberParent.Member.Name, expression.Member.Name, reportedSignatureSupport));
            }

            return(CreateFieldSelector(expression.Member.Name, null, reportedSignatureSupport));
        }