using System.Collections;
using System.Collections.Generic;
using System.Reflection;
+using System.Xml;
namespace Microsoft.Build.BuildEngine {
public class TargetCollection : ICollection, IEnumerable {
internal TargetCollection (Project project)
{
- this.targetsByName = new Dictionary <string, Target> ();
+ this.targetsByName = new Dictionary <string, Target> (StringComparer.InvariantCultureIgnoreCase);
this.parentProject = project;
}
- // This must create a new xml element and stuff.
[MonoTODO]
public Target AddNewTarget (string targetName)
{
- throw new NotImplementedException ();
+ if (targetName == null)
+ throw new InvalidProjectFileException (
+ "The required attribute \"Name\" is missing from element <Target>.");
+
+ XmlElement targetElement = parentProject.XmlDocument.CreateElement ("Target", Project.XmlNamespace);
+ parentProject.XmlDocument.DocumentElement.AppendChild (targetElement);
+ targetElement.SetAttribute ("Name", targetName);
+
+ Target t = new Target (targetElement, parentProject, null);
+
+ AddTarget (t);
+
+ return t;
}
internal void AddTarget (Target target)
{
+ if (targetsByName.ContainsKey (target.Name))
+ targetsByName.Remove (target.Name);
targetsByName.Add (target.Name, target);
}
public IEnumerator GetEnumerator ()
{
- foreach (KeyValuePair <string, Target> kvp in targetsByName) {
- yield return kvp.Key;
- }
+ foreach (KeyValuePair <string, Target> kvp in targetsByName)
+ yield return kvp.Value;
}
public void RemoveTarget (Target targetToRemove)
{
+ if (targetToRemove == null)
+ throw new ArgumentNullException ();
+
targetsByName.Remove (targetToRemove.Name);
}