BasicExpressionVisitor.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntity / System / Data / Common / CommandTrees / BasicExpressionVisitor.cs / 4 / BasicExpressionVisitor.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner  [....], [....]
//--------------------------------------------------------------------- 
 
using System.Collections.Generic;
using System.Diagnostics; 

using System.Data.Metadata.Edm;

namespace System.Data.Common.CommandTrees 
{
    ///  
    /// An abstract base type for types that implement the IExpressionVisitor interface to derive from. 
    /// 
    /*CQT_PUBLIC_API(*/internal/*)*/ abstract class BasicExpressionVisitor : DbExpressionVisitor 
    {
        #region protected API, may be overridden to add functionality at specific points in the traversal

        ///  
        /// Convenience method to visit the specified .
        ///  
        /// The DbUnaryExpression to visit. 
        ///  is null
        protected virtual void VisitUnaryExpression(DbUnaryExpression expression) 
        {
            VisitExpression(EntityUtil.CheckArgumentNull(expression, "expression").Argument);
        }
 
        /// 
        /// Convenience method to visit the specified . 
        ///  
        /// The DbBinaryExpression to visit.
        ///  is null 
        protected virtual void VisitBinaryExpression(DbBinaryExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            VisitExpression(expression.Left);
            VisitExpression(expression.Right); 
        } 

        ///  
        /// Convenience method to visit the specified .
        /// 
        /// The DbExpressionBinding to visit.
        ///  is null 
        protected virtual void VisitExpressionBindingPre(DbExpressionBinding binding)
        { 
            EntityUtil.CheckArgumentNull(binding, "binding"); 
            VisitExpression(binding.Expression);
        } 

        /// 
        /// Convenience method for post-processing after a DbExpressionBinding has been visited.
        ///  
        /// The previously visited DbExpressionBinding.
        protected virtual void VisitExpressionBindingPost(DbExpressionBinding binding) 
        { 
        }
 
        /// 
        /// Convenience method to visit the specified .
        /// 
        /// The DbGroupExpressionBinding to visit. 
        ///  is null
        protected virtual void VisitGroupExpressionBindingPre(DbGroupExpressionBinding binding) 
        { 
            EntityUtil.CheckArgumentNull(binding, "binding");
            VisitExpression(binding.Expression); 
        }

        /// 
        /// Convenience method indicating that the grouping keys of a  have been visited and the aggregates are now about to be visited. 
        /// 
        /// The DbGroupExpressionBinding of the DbGroupByExpression 
        protected virtual void VisitGroupExpressionBindingMid(DbGroupExpressionBinding binding) 
        {
        } 

        /// 
        /// Convenience method for post-processing after a DbGroupExpressionBinding has been visited.
        ///  
        /// The previously visited DbGroupExpressionBinding.
        protected virtual void VisitGroupExpressionBindingPost(DbGroupExpressionBinding binding) 
        { 
        }
 
        /// 
        /// Convenience method indicating that the body of a Lambda  is now about to be visited.
        /// 
        /// The Lambda function that is about to be visited 
        /// The expression that defines the body of the Lambda function that is about to be visited
        ///  is null 
        ///  is null 
        protected virtual void VisitLambdaFunctionPre(EdmFunction function, DbExpression body)
        { 
            EntityUtil.CheckArgumentNull(function, "function");
            EntityUtil.CheckArgumentNull(body, "body");
        }
 
        /// 
        /// Convenience method for post-processing after a Lambda DbFunctionExpression has been visited. 
        ///  
        /// The previously visited Lambda function.
        /// The expression that defines the body of the previously visited Lambda function 
        protected virtual void VisitLambdaFunctionPost(EdmFunction function, DbExpression body)
        {
        }
 
        #endregion
 
        #region public convenience API 

        ///  
        /// Convenience method to visit the specified , if non-null.
        /// 
        /// The expression to visit.
        ///  is null 
        public virtual void VisitExpression(DbExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression").Accept(this);
        } 

        /// 
        /// Convenience method to visit each  in the given list, if the list is non-null.
        ///  
        /// The list of expressions to visit.
        ///  is null 
        public virtual void VisitExpressionList(IList expressionList) 
        {
            EntityUtil.CheckArgumentNull(expressionList, "expressionList"); 
            for(int idx = 0; idx < expressionList.Count; idx++)
            {
                VisitExpression(expressionList[idx]);
            } 
        }
 
        ///  
        /// Convenience method to visit each  in the list, if the list is non-null.
        ///  
        /// The list of aggregates to visit.
        ///  is null
        public virtual void VisitAggregateList(IList aggregates)
        { 
            EntityUtil.CheckArgumentNull(aggregates, "aggregates");
            for(int idx = 0; idx < aggregates.Count; idx++) 
            { 
                VisitAggregate(aggregates[idx]);
            } 
        }

        /// 
        /// Convenience method to visit the specified . 
        /// 
        /// The aggregate to visit. 
        ///  is null 
        public virtual void VisitAggregate(DbAggregate aggregate)
        { 
            // #433613: PreSharp warning 56506: Parameter 'aggregate' to this public method must be validated: A null-dereference can occur here.
            VisitExpressionList(EntityUtil.CheckArgumentNull(aggregate, "aggregate").Arguments);
        }
 
        internal virtual void VisitRelatedEntityReferenceList(IList relatedEntityReferences)
        { 
            for (int idx = 0; idx < relatedEntityReferences.Count; idx++) 
            {
                this.VisitRelatedEntityReference(relatedEntityReferences[idx]); 
            }
        }

        internal virtual void VisitRelatedEntityReference(DbRelatedEntityRef relatedEntityRef) 
        {
            VisitExpression(relatedEntityRef.TargetEntityReference); 
        } 

        #endregion 

        #region DbExpressionVisitor Members

        ///  
        /// Called when an  of an otherwise unrecognized type is encountered.
        ///  
        /// The expression 
        ///  is null
        /// Always thrown if this method is called, since it indicates that  is of an unsupported type 
        public override void Visit(DbExpression expression)
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 

            throw EntityUtil.NotSupported(System.Data.Entity.Strings.Cqt_General_UnsupportedExpression(expression.GetType().FullName)); 
        } 

        ///  
        /// Visitor pattern method for .
        /// 
        /// The DbConstantExpression that is being visited.
        ///  is null 
        public override void Visit(DbConstantExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
        } 

        /// 
        /// Visitor pattern method for .
        ///  
        /// The DbNullExpression that is being visited.
        ///  is null 
        public override void Visit(DbNullExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbVariableReferenceExpression that is being visited. 
        ///  is null
        public override void Visit(DbVariableReferenceExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbParameterReferenceExpression that is being visited. 
        ///  is null
        public override void Visit(DbParameterReferenceExpression expression)
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbFunctionExpression that is being visited.
        ///  is null
        public override void Visit(DbFunctionExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression"); 

            VisitExpressionList(expression.Arguments); 
            if (expression.IsLambda)
            {
                Debug.Assert(expression.LambdaBody != null, "DbFunctionExpression.IsLambdaFunction returned true when DbFunctionExpression.LambdaBody == null");
 
                VisitLambdaFunctionPre(expression.Function, expression.LambdaBody);
                VisitExpression(expression.LambdaBody); 
                VisitLambdaFunctionPost(expression.Function, expression.LambdaBody); 
            }
        } 

#if METHOD_EXPRESSION
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The MethodExpression that is being visited. 
        ///  is null 
        public override void Visit(MethodExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");

            if (expression.Instance != null) 
            {
                VisitExpression(expression.Instance); 
            } 
            VisitExpressionList(expression.Arguments);
        } 
#endif

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbPropertyExpression that is being visited. 
        ///  is null 
        public override void Visit(DbPropertyExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");

            if(expression.Instance != null) 
            {
                VisitExpression(expression.Instance); 
            } 
        }
 
        /// 
        /// Visitor pattern method for .
        /// 
        /// The DbComparisonExpression that is being visited. 
        ///  is null
        public override void Visit(DbComparisonExpression expression) 
        { 
            VisitBinaryExpression(expression);
        } 

        /// 
        /// Visitor pattern method for .
        ///  
        /// The DbLikeExpression that is being visited.
        ///  is null 
        public override void Visit(DbLikeExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");

            VisitExpression(expression.Argument);
            VisitExpression(expression.Pattern); 
            VisitExpression(expression.Escape);
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbLimitExpression that is being visited.
        ///  is null
        public override void Visit(DbLimitExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression"); 

            VisitExpression(expression.Argument); 
            VisitExpression(expression.Limit);
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbIsNullExpression that is being visited. 
        ///  is null
        public override void Visit(DbIsNullExpression expression) 
        {
            VisitUnaryExpression(expression);
        }
 
        /// 
        /// Visitor pattern method for . 
        ///  
        /// The DbArithmeticExpression that is being visited.
        ///  is null 
        public override void Visit(DbArithmeticExpression expression)
        {
            VisitExpressionList(EntityUtil.CheckArgumentNull(expression, "expression").Arguments);
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbAndExpression that is being visited. 
        ///  is null
        public override void Visit(DbAndExpression expression)
        {
            VisitBinaryExpression(expression); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbOrExpression that is being visited.
        ///  is null
        public override void Visit(DbOrExpression expression)
        { 
            VisitBinaryExpression(expression);
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbNotExpression that is being visited.
        ///  is null
        public override void Visit(DbNotExpression expression) 
        {
            VisitUnaryExpression(expression); 
        } 

        ///  
        /// Visitor pattern method for .
        /// 
        /// The DbDistinctExpression that is being visited.
        ///  is null 
        public override void Visit(DbDistinctExpression expression)
        { 
            VisitUnaryExpression(expression); 
        }
 
        /// 
        /// Visitor pattern method for .
        /// 
        /// The DbElementExpression that is being visited. 
        ///  is null
        public override void Visit(DbElementExpression expression) 
        { 
            VisitUnaryExpression(expression);
        } 

        /// 
        /// Visitor pattern method for .
        ///  
        /// The DbIsEmptyExpression that is being visited.
        ///  is null 
        public override void Visit(DbIsEmptyExpression expression) 
        {
            VisitUnaryExpression(expression); 
        }

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbUnionAllExpression that is being visited. 
        ///  is null 
        public override void Visit(DbUnionAllExpression expression)
        { 
            VisitBinaryExpression(expression);
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbIntersectExpression that is being visited. 
        ///  is null
        public override void Visit(DbIntersectExpression expression) 
        {
            VisitBinaryExpression(expression);
        }
 
        /// 
        /// Visitor pattern method for . 
        ///  
        /// The DbExceptExpression that is being visited.
        ///  is null 
        public override void Visit(DbExceptExpression expression)
        {
            VisitBinaryExpression(expression);
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbOfTypeExpression that is being visited. 
        ///  is null
        public override void Visit(DbOfTypeExpression expression)
        {
            VisitUnaryExpression(expression); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbTreatExpression that is being visited.
        ///  is null
        public override void Visit(DbTreatExpression expression)
        { 
            VisitUnaryExpression(expression);
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbCastExpression that is being visited.
        ///  is null
        public override void Visit(DbCastExpression expression) 
        {
            VisitUnaryExpression(expression); 
        } 

        ///  
        /// Visitor pattern method for .
        /// 
        /// The DbIsOfExpression that is being visited.
        ///  is null 
        public override void Visit(DbIsOfExpression expression)
        { 
            VisitUnaryExpression(expression); 
        }
 
        /// 
        /// Visitor pattern method for .
        /// 
        /// The DbCaseExpression that is being visited. 
        ///  is null
        public override void Visit(DbCaseExpression expression) 
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 

            VisitExpressionList(expression.When);
            VisitExpressionList(expression.Then);
            VisitExpression(expression.Else); 
        }
 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbNewInstanceExpression that is being visited.
        ///  is null
        public override void Visit(DbNewInstanceExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression"); 
            VisitExpressionList(expression.Arguments);
            if (expression.HasRelatedEntityReferences) 
            {
                Debug.Assert(expression.RelatedEntityReferences != null, "HasRelatedEntityReferences returned true for null RelatedEntityReferences list?");
                this.VisitRelatedEntityReferenceList(expression.RelatedEntityReferences);
            } 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbRefExpression that is being visited.
        ///  is null
        public override void Visit(DbRefExpression expression)
        { 
            VisitUnaryExpression(expression);
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbRelationshipNavigationExpression that is being visited.
        ///  is null
        public override void Visit(DbRelationshipNavigationExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            VisitExpression(EntityUtil.CheckArgumentNull(expression, "expression").NavigationSource); 
        }
 
        /// 
        /// Visitor pattern method for .
        /// 
        /// The DeRefExpression that is being visited. 
        ///  is null
        public override void Visit(DbDerefExpression expression) 
        { 
            VisitUnaryExpression(expression);
        } 

        /// 
        /// Visitor pattern method for .
        ///  
        /// The DbRefKeyExpression that is being visited.
        ///  is null 
        public override void Visit(DbRefKeyExpression expression) 
        {
            VisitUnaryExpression(expression); 
        }

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbEntityRefExpression that is being visited. 
        ///  is null 
        public override void Visit(DbEntityRefExpression expression)
        { 
            VisitUnaryExpression(expression);
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbScanExpression that is being visited. 
        ///  is null
        public override void Visit(DbScanExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbFilterExpression that is being visited. 
        ///  is null
        public override void Visit(DbFilterExpression expression)
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            VisitExpressionBindingPre(expression.Input); 
            VisitExpression(expression.Predicate);
            VisitExpressionBindingPost(expression.Input); 
        }

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbProjectExpression that is being visited. 
        ///  is null 
        public override void Visit(DbProjectExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");

            VisitExpressionBindingPre(expression.Input); 
            VisitExpression(expression.Projection);
            VisitExpressionBindingPost(expression.Input); 
        } 

        ///  
        /// Visitor pattern method for .
        /// 
        /// The DbCrossJoinExpression that is being visited.
        ///  is null 
        public override void Visit(DbCrossJoinExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            foreach (DbExpressionBinding b in expression.Inputs)
            {
                VisitExpressionBindingPre(b);
            } 

            foreach (DbExpressionBinding b in expression.Inputs) 
            { 
                VisitExpressionBindingPost(b);
            } 
        }

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbJoinExpression that is being visited. 
        ///  is null 
        public override void Visit(DbJoinExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");

            VisitExpressionBindingPre(expression.Left); 
            VisitExpressionBindingPre(expression.Right);
 
            VisitExpression(expression.JoinCondition); 

            VisitExpressionBindingPost(expression.Left); 
            VisitExpressionBindingPost(expression.Right);
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbApplyExpression that is being visited. 
        ///  is null
        public override void Visit(DbApplyExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            VisitExpressionBindingPre(expression.Input);
 
            // #433613: PreSharp warning 56506: Parameter 'expression.Apply' to this public method must be validated: A null-dereference can occur here. 
            if (expression.Apply != null)
            { 
                VisitExpression(expression.Apply.Expression);
            }

            VisitExpressionBindingPost(expression.Input); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbExpression that is being visited.
        ///  is null
        public override void Visit(DbGroupByExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 
 
            VisitGroupExpressionBindingPre(expression.Input);
            VisitExpressionList(expression.Keys); 
            VisitGroupExpressionBindingMid(expression.Input);
            VisitAggregateList(expression.Aggregates);
            VisitGroupExpressionBindingPost(expression.Input);
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbSkipExpression that is being visited. 
        ///  is null
        public override void Visit(DbSkipExpression expression)
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            VisitExpressionBindingPre(expression.Input); 
            foreach (DbSortClause sortKey in expression.SortOrder)
            { 
                VisitExpression(sortKey.Expression);
            }
            VisitExpressionBindingPost(expression.Input);
            VisitExpression(expression.Count); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbSortExpression that is being visited.
        ///  is null
        public override void Visit(DbSortExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 
 
            VisitExpressionBindingPre(expression.Input);
            for(int idx = 0; idx < expression.SortOrder.Count; idx++) 
            {
                VisitExpression(expression.SortOrder[idx].Expression);
            }
            VisitExpressionBindingPost(expression.Input); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbQuantifierExpression that is being visited.
        ///  is null
        public override void Visit(DbQuantifierExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 
 
            VisitExpressionBindingPre(expression.Input);
            VisitExpression(expression.Predicate); 
            VisitExpressionBindingPost(expression.Input);
        }
        #endregion
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner  [....], [....]
//--------------------------------------------------------------------- 
 
using System.Collections.Generic;
using System.Diagnostics; 

using System.Data.Metadata.Edm;

namespace System.Data.Common.CommandTrees 
{
    ///  
    /// An abstract base type for types that implement the IExpressionVisitor interface to derive from. 
    /// 
    /*CQT_PUBLIC_API(*/internal/*)*/ abstract class BasicExpressionVisitor : DbExpressionVisitor 
    {
        #region protected API, may be overridden to add functionality at specific points in the traversal

        ///  
        /// Convenience method to visit the specified .
        ///  
        /// The DbUnaryExpression to visit. 
        ///  is null
        protected virtual void VisitUnaryExpression(DbUnaryExpression expression) 
        {
            VisitExpression(EntityUtil.CheckArgumentNull(expression, "expression").Argument);
        }
 
        /// 
        /// Convenience method to visit the specified . 
        ///  
        /// The DbBinaryExpression to visit.
        ///  is null 
        protected virtual void VisitBinaryExpression(DbBinaryExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            VisitExpression(expression.Left);
            VisitExpression(expression.Right); 
        } 

        ///  
        /// Convenience method to visit the specified .
        /// 
        /// The DbExpressionBinding to visit.
        ///  is null 
        protected virtual void VisitExpressionBindingPre(DbExpressionBinding binding)
        { 
            EntityUtil.CheckArgumentNull(binding, "binding"); 
            VisitExpression(binding.Expression);
        } 

        /// 
        /// Convenience method for post-processing after a DbExpressionBinding has been visited.
        ///  
        /// The previously visited DbExpressionBinding.
        protected virtual void VisitExpressionBindingPost(DbExpressionBinding binding) 
        { 
        }
 
        /// 
        /// Convenience method to visit the specified .
        /// 
        /// The DbGroupExpressionBinding to visit. 
        ///  is null
        protected virtual void VisitGroupExpressionBindingPre(DbGroupExpressionBinding binding) 
        { 
            EntityUtil.CheckArgumentNull(binding, "binding");
            VisitExpression(binding.Expression); 
        }

        /// 
        /// Convenience method indicating that the grouping keys of a  have been visited and the aggregates are now about to be visited. 
        /// 
        /// The DbGroupExpressionBinding of the DbGroupByExpression 
        protected virtual void VisitGroupExpressionBindingMid(DbGroupExpressionBinding binding) 
        {
        } 

        /// 
        /// Convenience method for post-processing after a DbGroupExpressionBinding has been visited.
        ///  
        /// The previously visited DbGroupExpressionBinding.
        protected virtual void VisitGroupExpressionBindingPost(DbGroupExpressionBinding binding) 
        { 
        }
 
        /// 
        /// Convenience method indicating that the body of a Lambda  is now about to be visited.
        /// 
        /// The Lambda function that is about to be visited 
        /// The expression that defines the body of the Lambda function that is about to be visited
        ///  is null 
        ///  is null 
        protected virtual void VisitLambdaFunctionPre(EdmFunction function, DbExpression body)
        { 
            EntityUtil.CheckArgumentNull(function, "function");
            EntityUtil.CheckArgumentNull(body, "body");
        }
 
        /// 
        /// Convenience method for post-processing after a Lambda DbFunctionExpression has been visited. 
        ///  
        /// The previously visited Lambda function.
        /// The expression that defines the body of the previously visited Lambda function 
        protected virtual void VisitLambdaFunctionPost(EdmFunction function, DbExpression body)
        {
        }
 
        #endregion
 
        #region public convenience API 

        ///  
        /// Convenience method to visit the specified , if non-null.
        /// 
        /// The expression to visit.
        ///  is null 
        public virtual void VisitExpression(DbExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression").Accept(this);
        } 

        /// 
        /// Convenience method to visit each  in the given list, if the list is non-null.
        ///  
        /// The list of expressions to visit.
        ///  is null 
        public virtual void VisitExpressionList(IList expressionList) 
        {
            EntityUtil.CheckArgumentNull(expressionList, "expressionList"); 
            for(int idx = 0; idx < expressionList.Count; idx++)
            {
                VisitExpression(expressionList[idx]);
            } 
        }
 
        ///  
        /// Convenience method to visit each  in the list, if the list is non-null.
        ///  
        /// The list of aggregates to visit.
        ///  is null
        public virtual void VisitAggregateList(IList aggregates)
        { 
            EntityUtil.CheckArgumentNull(aggregates, "aggregates");
            for(int idx = 0; idx < aggregates.Count; idx++) 
            { 
                VisitAggregate(aggregates[idx]);
            } 
        }

        /// 
        /// Convenience method to visit the specified . 
        /// 
        /// The aggregate to visit. 
        ///  is null 
        public virtual void VisitAggregate(DbAggregate aggregate)
        { 
            // #433613: PreSharp warning 56506: Parameter 'aggregate' to this public method must be validated: A null-dereference can occur here.
            VisitExpressionList(EntityUtil.CheckArgumentNull(aggregate, "aggregate").Arguments);
        }
 
        internal virtual void VisitRelatedEntityReferenceList(IList relatedEntityReferences)
        { 
            for (int idx = 0; idx < relatedEntityReferences.Count; idx++) 
            {
                this.VisitRelatedEntityReference(relatedEntityReferences[idx]); 
            }
        }

        internal virtual void VisitRelatedEntityReference(DbRelatedEntityRef relatedEntityRef) 
        {
            VisitExpression(relatedEntityRef.TargetEntityReference); 
        } 

        #endregion 

        #region DbExpressionVisitor Members

        ///  
        /// Called when an  of an otherwise unrecognized type is encountered.
        ///  
        /// The expression 
        ///  is null
        /// Always thrown if this method is called, since it indicates that  is of an unsupported type 
        public override void Visit(DbExpression expression)
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 

            throw EntityUtil.NotSupported(System.Data.Entity.Strings.Cqt_General_UnsupportedExpression(expression.GetType().FullName)); 
        } 

        ///  
        /// Visitor pattern method for .
        /// 
        /// The DbConstantExpression that is being visited.
        ///  is null 
        public override void Visit(DbConstantExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
        } 

        /// 
        /// Visitor pattern method for .
        ///  
        /// The DbNullExpression that is being visited.
        ///  is null 
        public override void Visit(DbNullExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbVariableReferenceExpression that is being visited. 
        ///  is null
        public override void Visit(DbVariableReferenceExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbParameterReferenceExpression that is being visited. 
        ///  is null
        public override void Visit(DbParameterReferenceExpression expression)
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbFunctionExpression that is being visited.
        ///  is null
        public override void Visit(DbFunctionExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression"); 

            VisitExpressionList(expression.Arguments); 
            if (expression.IsLambda)
            {
                Debug.Assert(expression.LambdaBody != null, "DbFunctionExpression.IsLambdaFunction returned true when DbFunctionExpression.LambdaBody == null");
 
                VisitLambdaFunctionPre(expression.Function, expression.LambdaBody);
                VisitExpression(expression.LambdaBody); 
                VisitLambdaFunctionPost(expression.Function, expression.LambdaBody); 
            }
        } 

#if METHOD_EXPRESSION
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The MethodExpression that is being visited. 
        ///  is null 
        public override void Visit(MethodExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");

            if (expression.Instance != null) 
            {
                VisitExpression(expression.Instance); 
            } 
            VisitExpressionList(expression.Arguments);
        } 
#endif

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbPropertyExpression that is being visited. 
        ///  is null 
        public override void Visit(DbPropertyExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");

            if(expression.Instance != null) 
            {
                VisitExpression(expression.Instance); 
            } 
        }
 
        /// 
        /// Visitor pattern method for .
        /// 
        /// The DbComparisonExpression that is being visited. 
        ///  is null
        public override void Visit(DbComparisonExpression expression) 
        { 
            VisitBinaryExpression(expression);
        } 

        /// 
        /// Visitor pattern method for .
        ///  
        /// The DbLikeExpression that is being visited.
        ///  is null 
        public override void Visit(DbLikeExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");

            VisitExpression(expression.Argument);
            VisitExpression(expression.Pattern); 
            VisitExpression(expression.Escape);
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbLimitExpression that is being visited.
        ///  is null
        public override void Visit(DbLimitExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression"); 

            VisitExpression(expression.Argument); 
            VisitExpression(expression.Limit);
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbIsNullExpression that is being visited. 
        ///  is null
        public override void Visit(DbIsNullExpression expression) 
        {
            VisitUnaryExpression(expression);
        }
 
        /// 
        /// Visitor pattern method for . 
        ///  
        /// The DbArithmeticExpression that is being visited.
        ///  is null 
        public override void Visit(DbArithmeticExpression expression)
        {
            VisitExpressionList(EntityUtil.CheckArgumentNull(expression, "expression").Arguments);
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbAndExpression that is being visited. 
        ///  is null
        public override void Visit(DbAndExpression expression)
        {
            VisitBinaryExpression(expression); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbOrExpression that is being visited.
        ///  is null
        public override void Visit(DbOrExpression expression)
        { 
            VisitBinaryExpression(expression);
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbNotExpression that is being visited.
        ///  is null
        public override void Visit(DbNotExpression expression) 
        {
            VisitUnaryExpression(expression); 
        } 

        ///  
        /// Visitor pattern method for .
        /// 
        /// The DbDistinctExpression that is being visited.
        ///  is null 
        public override void Visit(DbDistinctExpression expression)
        { 
            VisitUnaryExpression(expression); 
        }
 
        /// 
        /// Visitor pattern method for .
        /// 
        /// The DbElementExpression that is being visited. 
        ///  is null
        public override void Visit(DbElementExpression expression) 
        { 
            VisitUnaryExpression(expression);
        } 

        /// 
        /// Visitor pattern method for .
        ///  
        /// The DbIsEmptyExpression that is being visited.
        ///  is null 
        public override void Visit(DbIsEmptyExpression expression) 
        {
            VisitUnaryExpression(expression); 
        }

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbUnionAllExpression that is being visited. 
        ///  is null 
        public override void Visit(DbUnionAllExpression expression)
        { 
            VisitBinaryExpression(expression);
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbIntersectExpression that is being visited. 
        ///  is null
        public override void Visit(DbIntersectExpression expression) 
        {
            VisitBinaryExpression(expression);
        }
 
        /// 
        /// Visitor pattern method for . 
        ///  
        /// The DbExceptExpression that is being visited.
        ///  is null 
        public override void Visit(DbExceptExpression expression)
        {
            VisitBinaryExpression(expression);
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbOfTypeExpression that is being visited. 
        ///  is null
        public override void Visit(DbOfTypeExpression expression)
        {
            VisitUnaryExpression(expression); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbTreatExpression that is being visited.
        ///  is null
        public override void Visit(DbTreatExpression expression)
        { 
            VisitUnaryExpression(expression);
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbCastExpression that is being visited.
        ///  is null
        public override void Visit(DbCastExpression expression) 
        {
            VisitUnaryExpression(expression); 
        } 

        ///  
        /// Visitor pattern method for .
        /// 
        /// The DbIsOfExpression that is being visited.
        ///  is null 
        public override void Visit(DbIsOfExpression expression)
        { 
            VisitUnaryExpression(expression); 
        }
 
        /// 
        /// Visitor pattern method for .
        /// 
        /// The DbCaseExpression that is being visited. 
        ///  is null
        public override void Visit(DbCaseExpression expression) 
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 

            VisitExpressionList(expression.When);
            VisitExpressionList(expression.Then);
            VisitExpression(expression.Else); 
        }
 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbNewInstanceExpression that is being visited.
        ///  is null
        public override void Visit(DbNewInstanceExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression"); 
            VisitExpressionList(expression.Arguments);
            if (expression.HasRelatedEntityReferences) 
            {
                Debug.Assert(expression.RelatedEntityReferences != null, "HasRelatedEntityReferences returned true for null RelatedEntityReferences list?");
                this.VisitRelatedEntityReferenceList(expression.RelatedEntityReferences);
            } 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbRefExpression that is being visited.
        ///  is null
        public override void Visit(DbRefExpression expression)
        { 
            VisitUnaryExpression(expression);
        } 
 
        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbRelationshipNavigationExpression that is being visited.
        ///  is null
        public override void Visit(DbRelationshipNavigationExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            VisitExpression(EntityUtil.CheckArgumentNull(expression, "expression").NavigationSource); 
        }
 
        /// 
        /// Visitor pattern method for .
        /// 
        /// The DeRefExpression that is being visited. 
        ///  is null
        public override void Visit(DbDerefExpression expression) 
        { 
            VisitUnaryExpression(expression);
        } 

        /// 
        /// Visitor pattern method for .
        ///  
        /// The DbRefKeyExpression that is being visited.
        ///  is null 
        public override void Visit(DbRefKeyExpression expression) 
        {
            VisitUnaryExpression(expression); 
        }

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbEntityRefExpression that is being visited. 
        ///  is null 
        public override void Visit(DbEntityRefExpression expression)
        { 
            VisitUnaryExpression(expression);
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbScanExpression that is being visited. 
        ///  is null
        public override void Visit(DbScanExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbFilterExpression that is being visited. 
        ///  is null
        public override void Visit(DbFilterExpression expression)
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            VisitExpressionBindingPre(expression.Input); 
            VisitExpression(expression.Predicate);
            VisitExpressionBindingPost(expression.Input); 
        }

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbProjectExpression that is being visited. 
        ///  is null 
        public override void Visit(DbProjectExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");

            VisitExpressionBindingPre(expression.Input); 
            VisitExpression(expression.Projection);
            VisitExpressionBindingPost(expression.Input); 
        } 

        ///  
        /// Visitor pattern method for .
        /// 
        /// The DbCrossJoinExpression that is being visited.
        ///  is null 
        public override void Visit(DbCrossJoinExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            foreach (DbExpressionBinding b in expression.Inputs)
            {
                VisitExpressionBindingPre(b);
            } 

            foreach (DbExpressionBinding b in expression.Inputs) 
            { 
                VisitExpressionBindingPost(b);
            } 
        }

        /// 
        /// Visitor pattern method for . 
        /// 
        /// The DbJoinExpression that is being visited. 
        ///  is null 
        public override void Visit(DbJoinExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");

            VisitExpressionBindingPre(expression.Left); 
            VisitExpressionBindingPre(expression.Right);
 
            VisitExpression(expression.JoinCondition); 

            VisitExpressionBindingPost(expression.Left); 
            VisitExpressionBindingPost(expression.Right);
        }

        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbApplyExpression that is being visited. 
        ///  is null
        public override void Visit(DbApplyExpression expression) 
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            VisitExpressionBindingPre(expression.Input);
 
            // #433613: PreSharp warning 56506: Parameter 'expression.Apply' to this public method must be validated: A null-dereference can occur here. 
            if (expression.Apply != null)
            { 
                VisitExpression(expression.Apply.Expression);
            }

            VisitExpressionBindingPost(expression.Input); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbExpression that is being visited.
        ///  is null
        public override void Visit(DbGroupByExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 
 
            VisitGroupExpressionBindingPre(expression.Input);
            VisitExpressionList(expression.Keys); 
            VisitGroupExpressionBindingMid(expression.Input);
            VisitAggregateList(expression.Aggregates);
            VisitGroupExpressionBindingPost(expression.Input);
        } 

        ///  
        /// Visitor pattern method for . 
        /// 
        /// The DbSkipExpression that is being visited. 
        ///  is null
        public override void Visit(DbSkipExpression expression)
        {
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here. 
            EntityUtil.CheckArgumentNull(expression, "expression");
 
            VisitExpressionBindingPre(expression.Input); 
            foreach (DbSortClause sortKey in expression.SortOrder)
            { 
                VisitExpression(sortKey.Expression);
            }
            VisitExpressionBindingPost(expression.Input);
            VisitExpression(expression.Count); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbSortExpression that is being visited.
        ///  is null
        public override void Visit(DbSortExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 
 
            VisitExpressionBindingPre(expression.Input);
            for(int idx = 0; idx < expression.SortOrder.Count; idx++) 
            {
                VisitExpression(expression.SortOrder[idx].Expression);
            }
            VisitExpressionBindingPost(expression.Input); 
        }
 
        ///  
        /// Visitor pattern method for .
        ///  
        /// The DbQuantifierExpression that is being visited.
        ///  is null
        public override void Visit(DbQuantifierExpression expression)
        { 
            // #433613: PreSharp warning 56506: Parameter 'expression' to this public method must be validated: A null-dereference can occur here.
            EntityUtil.CheckArgumentNull(expression, "expression"); 
 
            VisitExpressionBindingPre(expression.Input);
            VisitExpression(expression.Predicate); 
            VisitExpressionBindingPost(expression.Input);
        }
        #endregion
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK