2 // ItemReference.cs: Represents "@(Reference)" in expression.
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
6 // Ankit Jain (jankit@novell.com)
8 // (C) 2005 Marek Sieradzki
9 // Copyright 2009 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using Microsoft.Build.Framework;
34 namespace Microsoft.Build.BuildEngine {
35 internal class ItemReference : IReference {
42 string original_string;
44 public ItemReference (string original_string, string itemName, string transform, string separator, int start, int length)
46 this.itemName = itemName;
49 this.original_string = original_string;
51 // Transform and separator are never expanded for item refs
52 if (transform != null) {
53 this.transform = new Expression ();
54 this.transform.Parse (transform, ParseOptions.AllowMetadata | ParseOptions.Split);
57 if (separator != null) {
58 this.separator = new Expression ();
59 this.separator.Parse (separator, ParseOptions.Split);
63 // when evaluating property, allowItems=false, so,
64 // ItemRef will _not_ get created, so this wont get hit
65 // when evaluating items, expand: true
66 // other cases, expand: true
67 public string ConvertToString (Project project, ExpressionOptions options)
70 if (project.TryGetEvaluatedItemByNameBatched (itemName, out group))
71 return group.ConvertToString (transform, separator, options);
76 public ITaskItem [] ConvertToITaskItemArray (Project project, ExpressionOptions options)
79 if (project.TryGetEvaluatedItemByNameBatched (itemName, out group))
80 return group.ConvertToITaskItemArray (transform, separator, options);
85 public string ItemName {
86 get { return itemName; }
89 public Expression Transform {
90 get { return transform; }
93 public Expression Separator {
94 get { return separator; }
97 public string OriginalString {
98 get { return original_string; }
102 get { return start; }
106 get { return start + length - 1; }
109 public override string ToString ()
111 return original_string;