1 //---------------------------------------------------------------------
2 // <copyright file="NodeCounter.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
12 using System.Globalization;
13 using System.Diagnostics;
14 using System.Data.Common;
15 using md=System.Data.Metadata.Edm;
17 namespace System.Data.Query.InternalTrees
20 /// Counts the number of nodes in a tree
22 internal class NodeCounter : BasicOpVisitorOfT<int>
25 /// Public entry point - Calculates the nubmer of nodes in the given subTree
27 /// <param name="subTree"></param>
28 /// <returns></returns>
29 internal static int Count(Node subTree)
31 NodeCounter counter = new NodeCounter();
32 return counter.VisitNode(subTree);
36 /// Common processing for all node types
37 /// Count = 1 (self) + count of children
39 /// <param name="n"></param>
40 /// <returns></returns>
41 protected override int VisitDefault(Node n)
44 foreach (Node child in n.Children)
46 count += VisitNode(child);