1 //------------------------------------------------------------------------------
2 // <copyright file="ModelMemberCollection.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace System.Activities.Presentation.Model {
10 using System.Collections;
11 using System.Collections.Generic;
12 using System.Diagnostics.CodeAnalysis;
13 using System.Activities.Presentation;
16 /// ModelMemberCollection is an abstract base class that
17 /// ModelPropertyCollection and ModelEventCollection derive from.
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 {
24 /// Internal constructor. Only our own collections can derive from this class.
26 internal ModelMemberCollection() { }
29 /// Searches the collection for the given key and returns it
30 /// if it is found. If not found, this throws an exception.
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] {
38 if (name == null) throw FxTrace.Exception.ArgumentNull("name");
39 return Find(name, true);
44 /// Searches the collection for the given key and returns it
45 /// if it is found. If not found, this throws an exception.
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] {
54 if (value == null) throw FxTrace.Exception.ArgumentNull("value");
55 return Find(value, true);
60 /// Searches the collection for the given key and returns it if it is
61 /// found. If not found, this returns null.
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);
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.
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);
83 /// Searches the collection for the given key and returns it if it is
84 /// found. If not found, this returns null.
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);
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.
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);
106 /// Returns an enumerator to enumerate values.
108 /// <returns></returns>
109 public abstract IEnumerator<TItemType> GetEnumerator();
111 #region IEnumerable Members
114 /// IEnumerable Implementation.
116 /// <returns></returns>
117 IEnumerator IEnumerable.GetEnumerator() {
118 return GetEnumerator();