2 // BuildItemGroup.cs: Represents a group of build items.
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2005 Marek Sieradzki
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Reflection;
32 using System.Collections;
34 using Microsoft.Build.Framework;
35 using Microsoft.Build.Utilities;
37 namespace Microsoft.Build.BuildEngine {
38 public class BuildItemGroup : ItemPropertyGroupingBase, IBuildItemGroup, IEnumerable {
40 XmlAttribute condition;
43 GroupingCollection parentCollection;
44 Project parentProject;
45 XmlElement itemGroupElement;
47 public BuildItemGroup ()
52 internal BuildItemGroup (Project project)
54 this.buildItems = new ArrayList ();
55 this.isImported = false;
56 this.parentProject = project;
59 public BuildItem AddNewItem (string itemName,
62 BuildItem bi = new BuildItem (itemName, itemInclude);
67 internal BuildItem AddFromParentItem (BuildItem bi)
69 BuildItem buildItem = new BuildItem (bi);
70 buildItems.Add (buildItem);
74 internal void AddItem (BuildItem buildItem)
76 buildItems.Add (buildItem);
79 internal void AddItem (string name, ITaskItem taskItem)
82 buildItem = new BuildItem (name, taskItem, this);
83 buildItems.Add (buildItem);
88 //FIXME: should this remove all build items?
89 buildItems = new ArrayList ();
92 public BuildItemGroup Clone (bool deepClone)
94 BuildItemGroup big = new BuildItemGroup ();
95 // FIXME: add copying of items
99 public override void Evaluate (BuildPropertyGroup parentPropertyBag,
100 bool ignoreCondition,
102 Hashtable conditionedPropertiesTable,
107 public IEnumerator GetEnumerator ()
109 return buildItems.GetEnumerator ();
112 public void RemoveItem (BuildItem itemToRemove)
114 buildItems.Remove (itemToRemove);
117 public void RemoveItemAt (int index)
119 buildItems.RemoveAt (index);
122 public BuildItem[] ToArray ()
125 array = new BuildItem [Count];
126 buildItems.CopyTo (array,0);
130 internal void BindToXml (XmlElement xmlElement)
132 if (xmlElement == null)
133 throw new ArgumentNullException ("xmlElement");
134 this.condition = xmlElement.GetAttributeNode ("Condition");
135 this.itemGroupElement = xmlElement;
136 foreach (XmlNode xn in xmlElement.ChildNodes) {
137 if (xn is XmlElement) {
138 XmlElement xe = (XmlElement) xn;
139 BuildItem bi = new BuildItem (xe.Name, this);
146 internal string ToString (Expression transform, string separator)
148 string[] items = new string [buildItems.Count];
150 foreach (BuildItem bi in buildItems)
151 items [i++] = bi.ToString (transform);
152 return String.Join (separator,items);
155 internal ITaskItem[] ToITaskItemArray (Expression transform)
157 ITaskItem[] array = new ITaskItem [buildItems.Count];
159 foreach (BuildItem item in buildItems)
160 array [i++] = item.ToITaskItem (transform);
164 public string Condition {
166 if (condition != null)
167 return condition.Value;
172 if (condition != null)
173 condition.Value = value;
179 if (buildItems != null)
180 return buildItems.Count;
186 public bool IsImported {
192 public BuildItem this[int index] {
194 return (BuildItem) buildItems [index];
198 internal GroupingCollection GroupingCollection {
199 get { return parentCollection; }
200 set { parentCollection = value; }
203 internal Project Project {
204 get { return parentProject; }