Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Query / InternalTrees / NodeCounter.cs
1 //---------------------------------------------------------------------
2 // <copyright file="NodeCounter.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 using System;
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;
16
17 namespace System.Data.Query.InternalTrees
18 {
19     /// <summary>
20     /// Counts the number of nodes in a tree
21     /// </summary>
22     internal class NodeCounter : BasicOpVisitorOfT<int>
23     {
24         /// <summary>
25         /// Public entry point - Calculates the nubmer of nodes in the given subTree
26         /// </summary>
27         /// <param name="subTree"></param>
28         /// <returns></returns>
29         internal static int Count(Node subTree)
30         {
31             NodeCounter counter = new NodeCounter();
32             return counter.VisitNode(subTree);
33         }
34
35         /// <summary>
36         /// Common processing for all node types
37         /// Count = 1 (self) + count of children
38         /// </summary>
39         /// <param name="n"></param>
40         /// <returns></returns>
41         protected override int VisitDefault(Node n)
42         {
43             int count = 1;
44             foreach (Node child in n.Children)
45             {
46                 count += VisitNode(child);
47             }
48             return count;
49         }
50     }
51 }
52
53