/// <summary>
        /// 
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        protected override Expression VisitBinary(BinaryExpression b)
        {
            LinqTridionAndOr currentLocalCriteriaNode = null;
            ExpressionType currentLocalExpressionType = ExpressionType.Add;

            if (b.Left is MemberExpression)
            {
                if (criteriaNodes == null)
                {
                    // We have a single where without AndAlso or OrElse if criteriaNodes is empty
                    criteriaNodes = new LinqTridionAnd();
                    currentCriteriaNode = criteriaNodes;
                }

                // CategorizationCriteria

                // KeywordCriteria

                switch (((MemberExpression)b.Left).Member.Name)
                {
                    case "IsMultimedia":
                        currentCriteriaNode.AddCriteria(new tridion.MultimediaCriteria((bool)((ConstantExpression)b.Right).Value));
                        break;
                    case "BinaryType":
                        currentCriteriaNode.AddCriteria(new tridion.BinaryTypeCriteria((string)((ConstantExpression)b.Right).Value));
                        break;
                    case "CategoryName":
                        currentCriteriaNode.AddCriteria(new tridion.CategoryCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;

                    case "ItemId":
                        currentCriteriaNode.AddCriteria(new tridion.ItemReferenceCriteria((int)((ConstantExpression)b.Right).Value));
                        break;
                    case "ItemSchemaId":
                        currentCriteriaNode.AddCriteria(new tridion.ItemSchemaCriteria((int)((ConstantExpression)b.Right).Value));
                        break;
                    case "ItemTemplateId":
                        currentCriteriaNode.AddCriteria(new tridion.ItemTemplateCriteria((int)((ConstantExpression)b.Right).Value));
                        break;
                    case "ItemTitle":
                        currentCriteriaNode.AddCriteria(new tridion.ItemTitleCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;
                    case "ItemType":
                        currentCriteriaNode.AddCriteria(new tridion.ItemTypeCriteria((int)((ConstantExpression)b.Right).Value));
                        break;
                    case "ItemCreationDate":
                        currentCriteriaNode.AddCriteria(new tridion.ItemCreationDateCriteria((DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;
                    case "ItemInitialPublishDate":
                        currentCriteriaNode.AddCriteria(new tridion.ItemInitialPublishDateCriteria((DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;
                    case "ItemLastPublishedDate":
                        currentCriteriaNode.AddCriteria(new tridion.ItemLastPublishedDateCriteria((DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;
                    case "ItemModificationDate":
                        currentCriteriaNode.AddCriteria(new tridion.ItemModificationDateCriteria((DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;

                    case "PageTemplateId":
                        currentCriteriaNode.AddCriteria(new tridion.PageTemplateCriteria((int)((ConstantExpression)b.Right).Value));
                        break;
                    case "PageURL":
                        currentCriteriaNode.AddCriteria(new tridion.PageURLCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;

                    case "PublicationId":
                        currentCriteriaNode.AddCriteria(new tridion.PublicationCriteria((int)((ConstantExpression)b.Right).Value));
                        break;
                    case "PublicationKey":
                        currentCriteriaNode.AddCriteria(new tridion.PublicationKeyCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;
                    case "PublicationMultimediaPath":
                        currentCriteriaNode.AddCriteria(new tridion.PublicationMultimediaPathCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;
                    case "PublicationMultimediaURL":
                        currentCriteriaNode.AddCriteria(new tridion.PublicationMultimediaURLCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;
                    case "PublicationPath":
                        currentCriteriaNode.AddCriteria(new tridion.PublicationPathCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;
                    case "PublicationTitle":
                        currentCriteriaNode.AddCriteria(new tridion.PublicationTitleCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;
                    case "PublicationURL":
                        currentCriteriaNode.AddCriteria(new tridion.PublicationURLCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;

                    case "SchemaTitle":
                        currentCriteriaNode.AddCriteria(new tridion.SchemaTitleCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                        break;

                    case "StructureGroupUri":
                        IStructureGroupUri sgu = (StructureGroupUri)((ConstantExpression)b.Right).Value;
                        currentCriteriaNode.AddCriteria(new tridion.StructureGroupCriteria(sgu.Uri, sgu.IncludeChild));
                        break;
                    case "StructureGroupDirectory":
                        IStructureGroupDirectory sgd = (StructureGroupDirectory)((ConstantExpression)b.Right).Value;
                        currentCriteriaNode.AddCriteria(new tridion.StructureGroupDirectoryCriteria(sgd.Directory, sgd.Operator ?? tridion.Criteria.Equal, sgd.IncludeChild));
                        break;
                    case "StructureGroupTitle":
                        IStructureGroupTitle sgt = (StructureGroupTitle)((ConstantExpression)b.Right).Value;
                        currentCriteriaNode.AddCriteria(new tridion.StructureGroupTitleCriteria(sgt.Title, sgt.Operator ?? tridion.Criteria.Equal, sgt.IncludeChild));
                        break;

                    case "TaxonomyUsedForIdentification":
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyUsedForIdentificationCriteria((bool)((ConstantExpression)b.Right).Value));
                        break;
                    case "TaxonomyUri":
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyCriteria((string)((ConstantExpression)b.Right).Value));
                        break;
                    case "TaxonomyKeyword":
                        ITaxonomyKeyword tk = (TaxonomyKeyword)((ConstantExpression)b.Right).Value;
                        if(tk.PublicationId != null && tk.TaxonomyId != null && tk.KeywordId != null)
                        {
                            currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordCriteria(tk.PublicationId.Value, tk.TaxonomyId.Value, tk.KeywordId.Value, tk.IncludeKeywordBranch));
                        }
                        else if(!string.IsNullOrEmpty(tk.TaxonomyUri) && !string.IsNullOrEmpty(tk.KeywordUri))
                        {
                            currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordCriteria(tk.TaxonomyUri, tk.KeywordUri, tk.IncludeKeywordBranch));
                        }
                        else
                        {
                            throw new NotSupportedException("Use either all the integer variables (PublicationId, TaxonomyId and KeywordId) or all the string variables (TaxonomyUri and KeywordUri) to create a correct KeywordCriteria");
                        }
                        break;
                    case "TaxonomyKeywordDescription":
                        ITaxonomyKeywordDescription tkd = (TaxonomyKeywordDescription)((ConstantExpression)b.Right).Value;
                        if(tkd.PublicationId != null && tkd.TaxonomyId != null)
                        {
                            currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordDescriptionCriteria(tkd.PublicationId.Value, tkd.TaxonomyId.Value, tkd.KeywordDescription, tkd.IncludeKeywordBranch, tkd.Operator ?? tridion.Criteria.Equal));
                        }
                        else if(!string.IsNullOrEmpty(tkd.TaxonomyUri))
                        {
                            currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordDescriptionCriteria(tkd.TaxonomyUri, tkd.KeywordDescription, tkd.IncludeKeywordBranch, tkd.Operator ?? tridion.Criteria.Equal));
                        }
                        else
                        {
                            throw new NotSupportedException("Use either all the integer variables (PublicationId, TaxonomyId) or all the string variable (TaxonomyUri) to create a correct KeywordCriteria");
                        }
                        break;
                    case "TaxonomyKeywordKey":
                        ITaxonomyKeywordKey tkk = (TaxonomyKeywordKey)((ConstantExpression)b.Right).Value;
                        if(tkk.PublicationId != null && tkk.TaxonomyId != null)
                        {
                            currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordKeyCriteria(tkk.PublicationId.Value, tkk.TaxonomyId.Value, tkk.KeywordKey, tkk.IncludeKeywordBranch, tkk.Operator ?? tridion.Criteria.Equal));
                        }
                        else if(!string.IsNullOrEmpty(tkk.TaxonomyUri))
                        {
                            currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordKeyCriteria(tkk.TaxonomyUri, tkk.KeywordKey, tkk.IncludeKeywordBranch, tkk.Operator ?? tridion.Criteria.Equal));
                        }
                        else
                        {
                            throw new NotSupportedException("Use either all the integer variables (PublicationId, TaxonomyId) or all the string variable (TaxonomyUri) to create a correct KeywordCriteria");
                        }
                        break;
                    case "TaxonomyKeywordName":
                        ITaxonomyKeywordName tkn = (TaxonomyKeywordName)((ConstantExpression)b.Right).Value;
                        if(tkn.PublicationId != null && tkn.TaxonomyId != null)
                        {
                            currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordNameCriteria(tkn.PublicationId.Value, tkn.TaxonomyId.Value, tkn.KeywordName, tkn.IncludeKeywordBranch, tkn.Operator ?? tridion.Criteria.Equal));
                        }
                        else if(!string.IsNullOrEmpty(tkn.TaxonomyUri))
                        {
                            currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordNameCriteria(tkn.TaxonomyUri, tkn.KeywordName, tkn.IncludeKeywordBranch, tkn.Operator ?? tridion.Criteria.Equal));
                        }
                        else
                        {
                            throw new NotSupportedException("Use either all the integer variables (PublicationId, TaxonomyId) or all the string variable (TaxonomyUri) to create a correct KeywordCriteria");
                        }
                        break;
                    default:
                        // It is a Custom Metadata Field
                        if (CheckMemberAttributes(((MemberExpression)b.Left).Member))
                        {
                            // Determine type of field
                            tridion.CustomMetaValueCriteria CustomMetadataCriteria = null;
                            switch (Type.GetTypeCode(((ConstantExpression)b.Right).Value.GetType()))
                            {
                                case TypeCode.DateTime:
                                    CustomMetadataCriteria = new tridion.CustomMetaValueCriteria(new tridion.CustomMetaKeyCriteria(((MemberExpression)b.Left).Member.Name), (DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType));
                                    break;
                                case TypeCode.Boolean:
                                case TypeCode.Byte:
                                case TypeCode.Decimal:
                                case TypeCode.Double:
                                case TypeCode.Int16:
                                case TypeCode.Int32:
                                case TypeCode.Int64:
                                case TypeCode.SByte:
                                case TypeCode.Single:
                                case TypeCode.UInt16:
                                case TypeCode.UInt32:
                                case TypeCode.UInt64:
                                    CustomMetadataCriteria = new tridion.CustomMetaValueCriteria(new tridion.CustomMetaKeyCriteria(((MemberExpression)b.Left).Member.Name), (float)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType));
                                    break;
                                case TypeCode.String:
                                    CustomMetadataCriteria = new tridion.CustomMetaValueCriteria(new tridion.CustomMetaKeyCriteria(((MemberExpression)b.Left).Member.Name), (string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType));
                                    break;
                                default:
                                    break;
                            }

                            if (CustomMetadataCriteria != null)
                            {
                                currentCriteriaNode.AddCriteria(CustomMetadataCriteria);
                            }
                        }
                        break;
                }
            }
            else
            {
                switch (b.NodeType)
                {
                    case ExpressionType.AndAlso:
                        if (currentExpressionType != b.NodeType)
                        {
                            if (criteriaNodes == null)
                            {
                                criteriaNodes = new LinqTridionAnd();
                                currentCriteriaNode = criteriaNodes;
                            }
                            else
                            {
                                currentCriteriaNode = criteriaNodes.AddChildCriteria(new LinqTridionAnd());
                            }
                            currentLocalCriteriaNode = currentCriteriaNode;
                            currentLocalExpressionType = b.NodeType;
                            currentExpressionType = b.NodeType;
                        }
                        break;
                    case ExpressionType.OrElse:
                        if (currentExpressionType != b.NodeType)
                        {
                            if (criteriaNodes == null)
                            {
                                criteriaNodes = new LinqTridionOr();
                                currentCriteriaNode = criteriaNodes;
                            }
                            else
                            {
                                currentCriteriaNode = criteriaNodes.AddChildCriteria(new LinqTridionOr());
                            }
                            currentLocalCriteriaNode = currentCriteriaNode;
                            currentLocalExpressionType = b.NodeType;
                            currentExpressionType = b.NodeType;
                        }
                        break;
                    case ExpressionType.Equal:
                        break;
                    case ExpressionType.NotEqual:
                        break;
                    case ExpressionType.LessThan:
                        break;
                    case ExpressionType.LessThanOrEqual:
                        break;
                    case ExpressionType.GreaterThan:
                        break;
                    case ExpressionType.GreaterThanOrEqual:
                        break;
                    default:
                        throw new NotSupportedException(string.Format("The binary operator '{0}' is not supported", b.NodeType));
                }
                this.Visit(b.Left);
                if (currentLocalCriteriaNode != null)
                {
                    currentCriteriaNode = currentLocalCriteriaNode;
                    currentExpressionType = currentLocalExpressionType;
                }
                this.Visit(b.Right);
            }
            return b;
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        protected override Expression VisitBinary(BinaryExpression b)
        {
            LinqTridionAndOr currentLocalCriteriaNode   = null;
            ExpressionType   currentLocalExpressionType = ExpressionType.Add;

            if (b.Left is MemberExpression)
            {
                if (criteriaNodes == null)
                {
                    // We have a single where without AndAlso or OrElse if criteriaNodes is empty
                    criteriaNodes       = new LinqTridionAnd();
                    currentCriteriaNode = criteriaNodes;
                }

                // CategorizationCriteria

                // KeywordCriteria

                switch (((MemberExpression)b.Left).Member.Name)
                {
                case "IsMultimedia":
                    currentCriteriaNode.AddCriteria(new tridion.MultimediaCriteria((bool)((ConstantExpression)b.Right).Value));
                    break;

                case "BinaryType":
                    currentCriteriaNode.AddCriteria(new tridion.BinaryTypeCriteria((string)((ConstantExpression)b.Right).Value));
                    break;

                case "CategoryName":
                    currentCriteriaNode.AddCriteria(new tridion.CategoryCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "ItemId":
                    currentCriteriaNode.AddCriteria(new tridion.ItemReferenceCriteria((int)((ConstantExpression)b.Right).Value));
                    break;

                case "ItemSchemaId":
                    currentCriteriaNode.AddCriteria(new tridion.ItemSchemaCriteria((int)((ConstantExpression)b.Right).Value));
                    break;

                case "ItemTemplateId":
                    currentCriteriaNode.AddCriteria(new tridion.ItemTemplateCriteria((int)((ConstantExpression)b.Right).Value));
                    break;

                case "ItemTitle":
                    currentCriteriaNode.AddCriteria(new tridion.ItemTitleCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "ItemType":
                    currentCriteriaNode.AddCriteria(new tridion.ItemTypeCriteria((int)((ConstantExpression)b.Right).Value));
                    break;

                case "ItemCreationDate":
                    currentCriteriaNode.AddCriteria(new tridion.ItemCreationDateCriteria((DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "ItemInitialPublishDate":
                    currentCriteriaNode.AddCriteria(new tridion.ItemInitialPublishDateCriteria((DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "ItemLastPublishedDate":
                    currentCriteriaNode.AddCriteria(new tridion.ItemLastPublishedDateCriteria((DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "ItemModificationDate":
                    currentCriteriaNode.AddCriteria(new tridion.ItemModificationDateCriteria((DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "PageTemplateId":
                    currentCriteriaNode.AddCriteria(new tridion.PageTemplateCriteria((int)((ConstantExpression)b.Right).Value));
                    break;

                case "PageURL":
                    currentCriteriaNode.AddCriteria(new tridion.PageURLCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "PublicationId":
                    currentCriteriaNode.AddCriteria(new tridion.PublicationCriteria((int)((ConstantExpression)b.Right).Value));
                    break;

                case "PublicationKey":
                    currentCriteriaNode.AddCriteria(new tridion.PublicationKeyCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "PublicationMultimediaPath":
                    currentCriteriaNode.AddCriteria(new tridion.PublicationMultimediaPathCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "PublicationMultimediaURL":
                    currentCriteriaNode.AddCriteria(new tridion.PublicationMultimediaURLCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "PublicationPath":
                    currentCriteriaNode.AddCriteria(new tridion.PublicationPathCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "PublicationTitle":
                    currentCriteriaNode.AddCriteria(new tridion.PublicationTitleCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "PublicationURL":
                    currentCriteriaNode.AddCriteria(new tridion.PublicationURLCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "SchemaTitle":
                    currentCriteriaNode.AddCriteria(new tridion.SchemaTitleCriteria((string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType)));
                    break;

                case "StructureGroupUri":
                    IStructureGroupUri sgu = (StructureGroupUri)((ConstantExpression)b.Right).Value;
                    currentCriteriaNode.AddCriteria(new tridion.StructureGroupCriteria(sgu.Uri, sgu.IncludeChild));
                    break;

                case "StructureGroupDirectory":
                    IStructureGroupDirectory sgd = (StructureGroupDirectory)((ConstantExpression)b.Right).Value;
                    currentCriteriaNode.AddCriteria(new tridion.StructureGroupDirectoryCriteria(sgd.Directory, sgd.Operator ?? tridion.Criteria.Equal, sgd.IncludeChild));
                    break;

                case "StructureGroupTitle":
                    IStructureGroupTitle sgt = (StructureGroupTitle)((ConstantExpression)b.Right).Value;
                    currentCriteriaNode.AddCriteria(new tridion.StructureGroupTitleCriteria(sgt.Title, sgt.Operator ?? tridion.Criteria.Equal, sgt.IncludeChild));
                    break;

                case "TaxonomyUsedForIdentification":
                    currentCriteriaNode.AddCriteria(new tridion.TaxonomyUsedForIdentificationCriteria((bool)((ConstantExpression)b.Right).Value));
                    break;

                case "TaxonomyUri":
                    currentCriteriaNode.AddCriteria(new tridion.TaxonomyCriteria((string)((ConstantExpression)b.Right).Value));
                    break;

                case "TaxonomyKeyword":
                    ITaxonomyKeyword tk = (TaxonomyKeyword)((ConstantExpression)b.Right).Value;
                    if (tk.PublicationId != null && tk.TaxonomyId != null && tk.KeywordId != null)
                    {
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordCriteria(tk.PublicationId.Value, tk.TaxonomyId.Value, tk.KeywordId.Value, tk.IncludeKeywordBranch));
                    }
                    else if (!string.IsNullOrEmpty(tk.TaxonomyUri) && !string.IsNullOrEmpty(tk.KeywordUri))
                    {
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordCriteria(tk.TaxonomyUri, tk.KeywordUri, tk.IncludeKeywordBranch));
                    }
                    else
                    {
                        throw new NotSupportedException("Use either all the integer variables (PublicationId, TaxonomyId and KeywordId) or all the string variables (TaxonomyUri and KeywordUri) to create a correct KeywordCriteria");
                    }
                    break;

                case "TaxonomyKeywordDescription":
                    ITaxonomyKeywordDescription tkd = (TaxonomyKeywordDescription)((ConstantExpression)b.Right).Value;
                    if (tkd.PublicationId != null && tkd.TaxonomyId != null)
                    {
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordDescriptionCriteria(tkd.PublicationId.Value, tkd.TaxonomyId.Value, tkd.KeywordDescription, tkd.IncludeKeywordBranch, tkd.Operator ?? tridion.Criteria.Equal));
                    }
                    else if (!string.IsNullOrEmpty(tkd.TaxonomyUri))
                    {
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordDescriptionCriteria(tkd.TaxonomyUri, tkd.KeywordDescription, tkd.IncludeKeywordBranch, tkd.Operator ?? tridion.Criteria.Equal));
                    }
                    else
                    {
                        throw new NotSupportedException("Use either all the integer variables (PublicationId, TaxonomyId) or all the string variable (TaxonomyUri) to create a correct KeywordCriteria");
                    }
                    break;

                case "TaxonomyKeywordKey":
                    ITaxonomyKeywordKey tkk = (TaxonomyKeywordKey)((ConstantExpression)b.Right).Value;
                    if (tkk.PublicationId != null && tkk.TaxonomyId != null)
                    {
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordKeyCriteria(tkk.PublicationId.Value, tkk.TaxonomyId.Value, tkk.KeywordKey, tkk.IncludeKeywordBranch, tkk.Operator ?? tridion.Criteria.Equal));
                    }
                    else if (!string.IsNullOrEmpty(tkk.TaxonomyUri))
                    {
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordKeyCriteria(tkk.TaxonomyUri, tkk.KeywordKey, tkk.IncludeKeywordBranch, tkk.Operator ?? tridion.Criteria.Equal));
                    }
                    else
                    {
                        throw new NotSupportedException("Use either all the integer variables (PublicationId, TaxonomyId) or all the string variable (TaxonomyUri) to create a correct KeywordCriteria");
                    }
                    break;

                case "TaxonomyKeywordName":
                    ITaxonomyKeywordName tkn = (TaxonomyKeywordName)((ConstantExpression)b.Right).Value;
                    if (tkn.PublicationId != null && tkn.TaxonomyId != null)
                    {
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordNameCriteria(tkn.PublicationId.Value, tkn.TaxonomyId.Value, tkn.KeywordName, tkn.IncludeKeywordBranch, tkn.Operator ?? tridion.Criteria.Equal));
                    }
                    else if (!string.IsNullOrEmpty(tkn.TaxonomyUri))
                    {
                        currentCriteriaNode.AddCriteria(new tridion.TaxonomyKeywordNameCriteria(tkn.TaxonomyUri, tkn.KeywordName, tkn.IncludeKeywordBranch, tkn.Operator ?? tridion.Criteria.Equal));
                    }
                    else
                    {
                        throw new NotSupportedException("Use either all the integer variables (PublicationId, TaxonomyId) or all the string variable (TaxonomyUri) to create a correct KeywordCriteria");
                    }
                    break;

                default:
                    // It is a Custom Metadata Field
                    if (CheckMemberAttributes(((MemberExpression)b.Left).Member))
                    {
                        // Determine type of field
                        tridion.CustomMetaValueCriteria CustomMetadataCriteria = null;
                        switch (Type.GetTypeCode(((ConstantExpression)b.Right).Value.GetType()))
                        {
                        case TypeCode.DateTime:
                            CustomMetadataCriteria = new tridion.CustomMetaValueCriteria(new tridion.CustomMetaKeyCriteria(((MemberExpression)b.Left).Member.Name), (DateTime)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType));
                            break;

                        case TypeCode.Boolean:
                        case TypeCode.Byte:
                        case TypeCode.Decimal:
                        case TypeCode.Double:
                        case TypeCode.Int16:
                        case TypeCode.Int32:
                        case TypeCode.Int64:
                        case TypeCode.SByte:
                        case TypeCode.Single:
                        case TypeCode.UInt16:
                        case TypeCode.UInt32:
                        case TypeCode.UInt64:
                            CustomMetadataCriteria = new tridion.CustomMetaValueCriteria(new tridion.CustomMetaKeyCriteria(((MemberExpression)b.Left).Member.Name), (float)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType));
                            break;

                        case TypeCode.String:
                            CustomMetadataCriteria = new tridion.CustomMetaValueCriteria(new tridion.CustomMetaKeyCriteria(((MemberExpression)b.Left).Member.Name), (string)((ConstantExpression)b.Right).Value, DetermineTridionFieldOperator(b.NodeType));
                            break;

                        default:
                            break;
                        }

                        if (CustomMetadataCriteria != null)
                        {
                            currentCriteriaNode.AddCriteria(CustomMetadataCriteria);
                        }
                    }
                    break;
                }
            }
            else
            {
                switch (b.NodeType)
                {
                case ExpressionType.AndAlso:
                    if (currentExpressionType != b.NodeType)
                    {
                        if (criteriaNodes == null)
                        {
                            criteriaNodes       = new LinqTridionAnd();
                            currentCriteriaNode = criteriaNodes;
                        }
                        else
                        {
                            currentCriteriaNode = criteriaNodes.AddChildCriteria(new LinqTridionAnd());
                        }
                        currentLocalCriteriaNode   = currentCriteriaNode;
                        currentLocalExpressionType = b.NodeType;
                        currentExpressionType      = b.NodeType;
                    }
                    break;

                case ExpressionType.OrElse:
                    if (currentExpressionType != b.NodeType)
                    {
                        if (criteriaNodes == null)
                        {
                            criteriaNodes       = new LinqTridionOr();
                            currentCriteriaNode = criteriaNodes;
                        }
                        else
                        {
                            currentCriteriaNode = criteriaNodes.AddChildCriteria(new LinqTridionOr());
                        }
                        currentLocalCriteriaNode   = currentCriteriaNode;
                        currentLocalExpressionType = b.NodeType;
                        currentExpressionType      = b.NodeType;
                    }
                    break;

                case ExpressionType.Equal:
                    break;

                case ExpressionType.NotEqual:
                    break;

                case ExpressionType.LessThan:
                    break;

                case ExpressionType.LessThanOrEqual:
                    break;

                case ExpressionType.GreaterThan:
                    break;

                case ExpressionType.GreaterThanOrEqual:
                    break;

                default:
                    throw new NotSupportedException(string.Format("The binary operator '{0}' is not supported", b.NodeType));
                }
                this.Visit(b.Left);
                if (currentLocalCriteriaNode != null)
                {
                    currentCriteriaNode   = currentLocalCriteriaNode;
                    currentExpressionType = currentLocalExpressionType;
                }
                this.Visit(b.Right);
            }
            return(b);
        }