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;
33 using System.Collections.Generic;
35 using Microsoft.Build.Framework;
36 using Microsoft.Build.Utilities;
38 namespace Microsoft.Build.BuildEngine {
39 public class BuildItemGroup : IEnumerable {
41 XmlAttribute condition;
43 List <BuildItem> buildItems;
44 GroupingCollection parentCollection;
45 Project parentProject;
46 XmlElement itemGroupElement;
48 public BuildItemGroup ()
53 internal BuildItemGroup (XmlElement xmlElement, Project project)
55 this.itemGroupElement = xmlElement;
56 this.buildItems = new List <BuildItem> ();
57 this.isImported = false;
58 this.parentProject = project;
63 this.condition = xmlElement.GetAttributeNode ("Condition");
64 foreach (XmlNode xn in xmlElement.ChildNodes) {
65 if (xn is XmlElement == false)
68 XmlElement xe = (XmlElement) xn;
69 BuildItem bi = new BuildItem (xe, this);
74 internal void Evaluate ()
76 foreach (BuildItem bi in buildItems) {
77 if (bi.Condition == String.Empty)
80 ConditionExpression ce = ConditionParser.ParseCondition (bi.Condition);
81 if (ce.BoolEvaluate (parentProject))
87 public BuildItem AddNewItem (string itemName,
90 return AddNewItem (itemName, itemInclude, false);
93 // FIXME: use expression
95 public BuildItem AddNewItem (string itemName,
97 bool treatItemIncludeAsLiteral)
99 BuildItem bi = new BuildItem (itemName, itemInclude);
104 internal void AddItem (BuildItem buildItem)
106 buildItems.Add (buildItem);
109 internal void AddItem (string name, ITaskItem taskItem)
112 buildItem = new BuildItem (name, taskItem);
113 buildItems.Add (buildItem);
119 //FIXME: should this remove all build items?
120 buildItems = new List <BuildItem> ();
124 public BuildItemGroup Clone (bool deepClone)
126 BuildItemGroup big = new BuildItemGroup ();
127 // FIXME: add copying of items
131 public IEnumerator GetEnumerator ()
133 return buildItems.GetEnumerator ();
137 public void RemoveItem (BuildItem itemToRemove)
139 buildItems.Remove (itemToRemove);
143 public void RemoveItemAt (int index)
145 buildItems.RemoveAt (index);
148 public BuildItem[] ToArray ()
150 return buildItems.ToArray ();
153 internal string ConvertToString (OldExpression transform,
154 OldExpression separator)
156 string separatorString;
158 if (separator == null)
159 separatorString = ";";
161 separatorString = (string) separator.ConvertTo (typeof (string));
163 string[] items = new string [buildItems.Count];
165 foreach (BuildItem bi in buildItems)
166 items [i++] = bi.ConvertToString (transform);
167 return String.Join (separatorString, items);
170 internal ITaskItem[] ConvertToITaskItemArray (OldExpression transform)
172 ITaskItem[] array = new ITaskItem [buildItems.Count];
174 foreach (BuildItem item in buildItems)
175 array [i++] = item.ConvertToITaskItem (transform);
179 public string Condition {
181 if (condition != null)
182 return condition.Value;
187 if (condition != null)
188 condition.Value = value;
194 if (buildItems != null)
195 return buildItems.Count;
201 public bool IsImported {
207 public BuildItem this [int index] {
209 return buildItems [index];
213 internal GroupingCollection GroupingCollection {
214 get { return parentCollection; }
215 set { parentCollection = value; }
218 internal Project Project {
219 get { return parentProject; }
222 internal bool FromXml {
224 return itemGroupElement != null;