[amd64/tramp] hide interpreter specific trampoline behind ifdef
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Interaction / Model / ModelMemberCollection.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="ModelMemberCollection.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6
7 namespace System.Activities.Presentation.Model {
8
9     using System;
10     using System.Collections;
11     using System.Collections.Generic;
12     using System.Diagnostics.CodeAnalysis;
13     using System.Activities.Presentation;
14
15     /// <summary>
16     /// ModelMemberCollection is an abstract base class that 
17     /// ModelPropertyCollection and ModelEventCollection derive from.
18     /// </summary>
19     /// <typeparam name="TItemType">The type of item the collection represents.</typeparam>
20     /// <typeparam name="TFindType">The type that should be used as a key in "Find" methods.</typeparam>
21     public abstract class ModelMemberCollection<TItemType, TFindType> : IEnumerable<TItemType>, IEnumerable {
22
23         /// <summary>
24         /// Internal constructor.  Only our own collections can derive from this class.
25         /// </summary>
26         internal ModelMemberCollection() { }
27
28         /// <summary>
29         /// Searches the collection for the given key and returns it 
30         /// if it is found.  If not found, this throws an exception.
31         /// </summary>
32         /// <param name="name"></param>
33         /// <returns></returns>
34         /// <exception cref="ArgumentNullException">if name is null.</exception>
35         /// <exception cref="ArgumentException">if name is not found.</exception>
36         public TItemType this[string name] {
37             get {
38                 if (name == null) throw FxTrace.Exception.ArgumentNull("name");
39                 return Find(name, true);
40             }
41         }
42
43         /// <summary>
44         /// Searches the collection for the given key and returns it 
45         /// if it is found.  If not found, this throws an exception.
46         /// </summary>
47         /// <param name="value"></param>
48         /// <returns></returns>
49         /// <exception cref="ArgumentNullException">if value is null.</exception>
50         /// <exception cref="ArgumentException">if value is not found.</exception>
51         [SuppressMessage("Microsoft.Design", "CA1043:UseIntegralOrStringArgumentForIndexers")]
52         public TItemType this[TFindType value] {
53             get {
54                 if (value == null) throw FxTrace.Exception.ArgumentNull("value");
55                 return Find(value, true);
56             }
57         }
58
59         /// <summary>
60         /// Searches the collection for the given key and returns it if it is 
61         /// found.  If not found, this returns null.
62         /// </summary>
63         /// <param name="name"></param>
64         /// <returns></returns>
65         /// <exception cref="ArgumentNullException">if name is null.</exception>
66         public TItemType Find(string name) {
67             if (name == null) throw FxTrace.Exception.ArgumentNull("name");
68             return Find(name, false);
69         }
70
71         /// <summary>
72         /// Searches the collection for the given key and returns it if it is 
73         /// found.  If not found, this throws an exception or returns null, 
74         /// depending on the value passed to throwOnError.
75         /// </summary>
76         /// <param name="name"></param>
77         /// <param name="throwOnError"></param>
78         /// <returns></returns>
79         /// <exception cref="ArgumentException">if name is not found and throwOnError is true.</exception>
80         protected abstract TItemType Find(string name, bool throwOnError);
81
82         /// <summary>
83         /// Searches the collection for the given key and returns it if it is 
84         /// found.  If not found, this returns null.
85         /// </summary>
86         /// <param name="value"></param>
87         /// <returns></returns>
88         /// <exception cref="ArgumentNullException">if value is null.</exception>
89         public TItemType Find(TFindType value) {
90             if (value == null) throw FxTrace.Exception.ArgumentNull("value");
91             return Find(value, false);
92         }
93
94         /// <summary>
95         /// Searches the collection for the given key and returns it if it is 
96         /// found.  If not found, this throws an exception or returns null, 
97         /// depending on the value passed to throwOnError.
98         /// </summary>
99         /// <param name="value"></param>
100         /// <param name="throwOnError"></param>
101         /// <returns></returns>
102         /// <exception cref="ArgumentException">if value is not found and throwOnError is true.</exception>
103         protected abstract TItemType Find(TFindType value, bool throwOnError);
104
105         /// <summary>
106         /// Returns an enumerator to enumerate values.
107         /// </summary>
108         /// <returns></returns>
109         public abstract IEnumerator<TItemType> GetEnumerator();
110
111         #region IEnumerable Members
112
113         /// <summary>
114         /// IEnumerable Implementation.
115         /// </summary>
116         /// <returns></returns>
117         IEnumerator IEnumerable.GetEnumerator() {
118             return GetEnumerator();
119         }
120
121         #endregion
122     }
123 }