Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Core / Castle.Core / Model / LifecycleStepCollection.cs
bloba99136741524d675afb57e6677db23ad99765f8b
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;
19 using System.Collections.Generic;
21 public enum LifecycleStepType
23 Commission,
24 Decommission
27 /// <summary>
28 /// Represents a collection of ordered lifecycle steps.
29 /// </summary>
30 #if !SILVERLIGHT
31 [Serializable]
32 #endif
33 public class LifecycleStepCollection : ICollection
35 private static object _syncRoot = new object();
36 private List<object> commissionSteps;
37 private List<object> decommissionSteps;
39 /// <summary>
40 /// Initializes a new instance of the <see cref="LifecycleStepCollection"/> class.
41 /// </summary>
42 public LifecycleStepCollection()
44 commissionSteps = new List<object>();
45 decommissionSteps = new List<object>();
48 /// <summary>
49 /// Returns all steps for the commission phase
50 /// </summary>
51 /// <returns></returns>
52 public object[] GetCommissionSteps()
54 object[] steps = new object[commissionSteps.Count];
55 commissionSteps.CopyTo(steps, 0);
56 return steps;
59 /// <summary>
60 /// Returns all steps for the decommission phase
61 /// </summary>
62 /// <returns></returns>
63 public object[] GetDecommissionSteps()
65 object[] steps = new object[decommissionSteps.Count];
66 decommissionSteps.CopyTo(steps, 0);
67 return steps;
70 /// <summary>
71 /// Gets a value indicating whether this instance has commission steps.
72 /// </summary>
73 /// <value>
74 /// <c>true</c> if this instance has commission steps; otherwise, <c>false</c>.
75 /// </value>
76 public bool HasCommissionSteps
78 get { return commissionSteps.Count != 0; }
81 /// <summary>
82 /// Gets a value indicating whether this instance has decommission steps.
83 /// </summary>
84 /// <value>
85 /// <c>true</c> if this instance has decommission steps; otherwise, <c>false</c>.
86 /// </value>
87 public bool HasDecommissionSteps
89 get { return decommissionSteps.Count != 0; }
92 /// <summary>
93 /// Adds a step to the commission or decomission phases.
94 /// </summary>
95 /// <param name="type"></param>
96 /// <param name="stepImplementation"></param>
97 public void Add(LifecycleStepType type, object stepImplementation)
99 if (stepImplementation == null) throw new ArgumentNullException("stepImplementation");
101 if (type == LifecycleStepType.Commission)
103 commissionSteps.Add(stepImplementation);
105 else
107 decommissionSteps.Add(stepImplementation);
111 /// <summary>
112 /// Copies the elements of
113 /// the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
114 /// </summary>
115 /// <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>
116 /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
117 /// <exception cref="T:System.ArgumentNullException">
118 /// <paramref name="array"/> is <see langword="null"/>.</exception>
119 /// <exception cref="T:System.ArgumentOutOfRangeException">
120 /// <paramref name="index"/> is less than zero.</exception>
121 /// <exception cref="T:System.ArgumentException">
122 /// <para>
123 /// <paramref name="array"/> is multidimensional.</para>
124 /// <para>-or-</para>
125 /// <para>
126 /// <paramref name="index"/> is equal to or greater than the length of <paramref name="array"/>.</para>
127 /// <para>-or-</para>
128 /// <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>
129 /// </exception>
130 /// <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>
131 public void CopyTo(Array array, int index)
133 throw new NotImplementedException();
136 /// <summary>
137 /// Gets the number of
138 /// elements contained in the <see cref="T:System.Collections.ICollection"/>.
139 /// </summary>
140 /// <value></value>
141 public int Count
143 get { return commissionSteps.Count + decommissionSteps.Count; }
146 /// <summary>
147 /// Gets an object that
148 /// can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.
149 /// </summary>
150 /// <value></value>
151 public object SyncRoot
153 get { return _syncRoot; }
156 /// <summary>
157 /// Gets a value
158 /// indicating whether access to the <see cref="T:System.Collections.ICollection"/> is synchronized
159 /// (thread-safe).
160 /// </summary>
161 /// <value></value>
162 public bool IsSynchronized
164 get { return false; }
167 /// <summary>
168 /// Returns an enumerator that can iterate through a collection.
169 /// </summary>
170 /// <returns>
171 /// An <see cref="T:System.Collections.IEnumerator"/>
172 /// that can be used to iterate through the collection.
173 /// </returns>
174 public IEnumerator GetEnumerator()
176 List<object> newList = new List<object>(commissionSteps);
177 newList.AddRange(decommissionSteps);
178 return newList.GetEnumerator();