1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System.Collections;
6 using System.Globalization;
7 
8 namespace System.Diagnostics
9 {
10     /// <summary>
11     ///     The collection returned from  the <see cref='System.Diagnostics.PerformanceCounterCategory.ReadCategory'/> method.
12     ///     that contains all the counter and instance data.
13     ///     The collection contains an InstanceDataCollection object for each counter.  Each InstanceDataCollection
14     ///     object contains the performance data for all counters for that instance.  In other words the data is
15     ///     indexed by counter name and then by instance name.
16     /// </summary>
17     public class InstanceDataCollectionCollection : DictionaryBase
18     {
19         [Obsolete("This constructor has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.ReadCategory() to get an instance of this collection instead.  http://go.microsoft.com/fwlink/?linkid=14202")]
InstanceDataCollectionCollection()20         public InstanceDataCollectionCollection() : base() { }
21 
22         public InstanceDataCollection this[string counterName]
23         {
24             get
25             {
26                 if (counterName == null)
27                     throw new ArgumentNullException(nameof(counterName));
28 
29                 object objectName = counterName.ToLower(CultureInfo.InvariantCulture);
30                 return (InstanceDataCollection)Dictionary[objectName];
31             }
32         }
33 
34         public ICollection Keys
35         {
36             get { return Dictionary.Keys; }
37         }
38 
39         public ICollection Values
40         {
41             get
42             {
43                 return Dictionary.Values;
44             }
45         }
46 
Add(string counterName, InstanceDataCollection value)47         internal void Add(string counterName, InstanceDataCollection value)
48         {
49             object objectName = counterName.ToLower(CultureInfo.InvariantCulture);
50             Dictionary.Add(objectName, value);
51         }
52 
Contains(string counterName)53         public bool Contains(string counterName)
54         {
55             if (counterName == null)
56                 throw new ArgumentNullException(nameof(counterName));
57 
58             object objectName = counterName.ToLower(CultureInfo.InvariantCulture);
59             return Dictionary.Contains(objectName);
60         }
61 
CopyTo(InstanceDataCollection[] counters, int index)62         public void CopyTo(InstanceDataCollection[] counters, int index)
63         {
64             Dictionary.Values.CopyTo((Array)counters, index);
65         }
66     }
67 }
68