NodeCounter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Query / InternalTrees / NodeCounter.cs / 1305376 / NodeCounter.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner  [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 

using System; 
using System.Collections.Generic;
using System.Globalization;
using System.Diagnostics;
using System.Data.Common; 
using md=System.Data.Metadata.Edm;
 
namespace System.Data.Query.InternalTrees 
{
    ///  
    /// Counts the number of nodes in a tree
    /// 
    internal class NodeCounter : BasicOpVisitorOfT
    { 
        /// 
        /// Public entry point - Calculates the nubmer of nodes in the given subTree 
        ///  
        /// 
        ///  
        internal static int Count(Node subTree)
        {
            NodeCounter counter = new NodeCounter();
            return counter.VisitNode(subTree); 
        }
 
        ///  
        /// Common processing for all node types
        /// Count = 1 (self) + count of children 
        /// 
        /// 
        /// 
        protected override int VisitDefault(Node n) 
        {
            int count = 1; 
            foreach (Node child in n.Children) 
            {
                count += VisitNode(child); 
            }
            return count;
        }
    } 
}
 
 

// 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