// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#if NET_2_0
+
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Reflection;
+using System.Xml;
namespace Microsoft.Build.BuildEngine {
- public class TargetCollection : ITargetCollection, ICollection, IEnumerable {
+ public class TargetCollection : ICollection, IEnumerable {
- IDictionary targetsByName;
- Project parentProject;
+ Dictionary <string, Target> targetsByName;
+ Project parentProject;
internal TargetCollection (Project project)
{
- this.targetsByName = new Hashtable ();
+ this.targetsByName = new Dictionary <string, Target> (StringComparer.InvariantCultureIgnoreCase);
this.parentProject = project;
}
-
+
+ [MonoTODO]
public Target AddNewTarget (string targetName)
{
- Target t;
+ if (targetName == null)
+ throw new InvalidProjectFileException (
+ "The required attribute \"Name\" is missing from element <Target>.");
+
+ // FIXME: test it
+ if (targetsByName.ContainsKey (targetName))
+ throw new Exception ("target already exists");
+
+ XmlElement targetElement = parentProject.XmlDocument.CreateElement ("Target", Project.XmlNamespace);
+ parentProject.XmlDocument.DocumentElement.AppendChild (targetElement);
+ targetElement.SetAttribute ("Name", targetName);
+
+ Target t = new Target (targetElement, parentProject, null);
- t = new Target (parentProject, targetName);
- targetsByName.Add (targetName, t);
+ AddTarget (t);
return t;
}
- public void CopyTo (Array array, int index)
+ internal void AddTarget (Target target)
{
- targetsByName.Values.CopyTo (array, index);
+ targetsByName.Add (target.Name, target);
}
- public void CopyToStronglyTypedArray (Target[] array,
- int index)
+ public void CopyTo (Array array, int index)
{
- if (array == null)
- throw new ArgumentNullException ("array");
- if (index < 0)
- throw new ArgumentOutOfRangeException ("index");
- if (array.Rank > 1)
- throw new ArgumentException ("array is multidimensional");
- if ((array.Length > 0) && (index >= array.Length))
- throw new ArgumentException ("index is equal or greater than array.Length");
- if (index + targetsByName.Count > array.Length)
- throw new ArgumentException ("Not enough room from index to end of array for this BuildPropertyGroupCollection");
-
- IEnumerator it = GetEnumerator ();
- int i = index;
- while (it.MoveNext ()) {
- array.SetValue((Target) it.Current, i++);
- }
+ targetsByName.Values.CopyTo ((Target[]) array, index);
}
public bool Exists (string targetName)
{
- return targetsByName.Contains (targetName);
+ return targetsByName.ContainsKey (targetName);
}
public IEnumerator GetEnumerator ()
{
- foreach (DictionaryEntry de in targetsByName) {
- yield return (Target)de.Key;
- }
+ foreach (KeyValuePair <string, Target> kvp in targetsByName)
+ yield return kvp.Value;
}
public void RemoveTarget (Target targetToRemove)
}
}
- public Target this[string index] {
+ public Target this [string index] {
get {
- return (Target) targetsByName [index];
+ if (targetsByName.ContainsKey (index))
+ return targetsByName [index];
+ else
+ return null;
}
}
}
}
+
+#endif