Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Core / Castle.Core / Model / LifecycleStepCollection.cs
blob46551f0127e33b22ee6ac0bf0e9bef1c0d503d29
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Core
17 using System;
18 using System.Collections;
20 public enum LifecycleStepType
22 Commission,
23 Decommission
26 /// <summary>
27 /// Represents a collection of ordered lifecycle steps.
28 /// </summary>
29 [Serializable]
30 public class LifecycleStepCollection : ICollection
32 private IList commissionSteps;
33 private IList decommissionSteps;
35 /// <summary>
36 /// Initializes a new instance of the <see cref="LifecycleStepCollection"/> class.
37 /// </summary>
38 public LifecycleStepCollection()
40 commissionSteps = new ArrayList();
41 decommissionSteps = new ArrayList();
44 /// <summary>
45 /// Returns all steps for the commission phase
46 /// </summary>
47 /// <returns></returns>
48 public object[] GetCommissionSteps()
50 object[] steps = new object[commissionSteps.Count];
51 commissionSteps.CopyTo(steps, 0);
52 return steps;
55 /// <summary>
56 /// Returns all steps for the decommission phase
57 /// </summary>
58 /// <returns></returns>
59 public object[] GetDecommissionSteps()
61 object[] steps = new object[decommissionSteps.Count];
62 decommissionSteps.CopyTo(steps, 0);
63 return steps;
66 /// <summary>
67 /// Gets a value indicating whether this instance has commission steps.
68 /// </summary>
69 /// <value>
70 /// <c>true</c> if this instance has commission steps; otherwise, <c>false</c>.
71 /// </value>
72 public bool HasCommissionSteps
74 get { return commissionSteps.Count != 0; }
77 /// <summary>
78 /// Gets a value indicating whether this instance has decommission steps.
79 /// </summary>
80 /// <value>
81 /// <c>true</c> if this instance has decommission steps; otherwise, <c>false</c>.
82 /// </value>
83 public bool HasDecommissionSteps
85 get { return decommissionSteps.Count != 0; }
88 /// <summary>
89 /// Adds a step to the commission or decomission phases.
90 /// </summary>
91 /// <param name="type"></param>
92 /// <param name="stepImplementation"></param>
93 public void Add(LifecycleStepType type, object stepImplementation)
95 if (stepImplementation == null) throw new ArgumentNullException("stepImplementation");
97 if (type == LifecycleStepType.Commission)
99 commissionSteps.Add(stepImplementation);
101 else
103 decommissionSteps.Add(stepImplementation);
107 /// <summary>
108 /// Copies the elements of
109 /// the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
110 /// </summary>
111 /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"/>. The <see cref="T:System.Array"/> must have zero-based indexing.</param>
112 /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
113 /// <exception cref="T:System.ArgumentNullException">
114 /// <paramref name="array"/> is <see langword="null"/>.</exception>
115 /// <exception cref="T:System.ArgumentOutOfRangeException">
116 /// <paramref name="index"/> is less than zero.</exception>
117 /// <exception cref="T:System.ArgumentException">
118 /// <para>
119 /// <paramref name="array"/> is multidimensional.</para>
120 /// <para>-or-</para>
121 /// <para>
122 /// <paramref name="index"/> is equal to or greater than the length of <paramref name="array"/>.</para>
123 /// <para>-or-</para>
124 /// <para>The number of elements in the source <see cref="T:System.Collections.ICollection"/> is greater than the available space from <paramref name="index"/> to the end of the destination <paramref name="array"/>.</para>
125 /// </exception>
126 /// <exception cref="T:System.InvalidCastException">The type of the source <see cref="T:System.Collections.ICollection"/> cannot be cast automatically to the type of the destination <paramref name="array"/>.</exception>
127 public void CopyTo(Array array, int index)
129 throw new NotImplementedException();
132 /// <summary>
133 /// Gets the number of
134 /// elements contained in the <see cref="T:System.Collections.ICollection"/>.
135 /// </summary>
136 /// <value></value>
137 public int Count
139 get { return commissionSteps.Count + decommissionSteps.Count; }
142 /// <summary>
143 /// Gets an object that
144 /// can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.
145 /// </summary>
146 /// <value></value>
147 public object SyncRoot
149 get { return commissionSteps.SyncRoot; }
152 /// <summary>
153 /// Gets a value
154 /// indicating whether access to the <see cref="T:System.Collections.ICollection"/> is synchronized
155 /// (thread-safe).
156 /// </summary>
157 /// <value></value>
158 public bool IsSynchronized
160 get { return commissionSteps.IsSynchronized; }
163 /// <summary>
164 /// Returns an enumerator that can iterate through a collection.
165 /// </summary>
166 /// <returns>
167 /// An <see cref="T:System.Collections.IEnumerator"/>
168 /// that can be used to iterate through the collection.
169 /// </returns>
170 public IEnumerator GetEnumerator()
172 ArrayList newList = new ArrayList(commissionSteps);
173 newList.AddRange(decommissionSteps);
174 return newList.GetEnumerator();