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.
33 using System
.Collections
;
34 using Microsoft
.Build
.Framework
;
36 namespace Microsoft
.Build
.BuildEngine
{
37 internal class ItemReference
: IReference
{
44 string original_string
;
46 public ItemReference (string original_string
, string itemName
, string transform
, string separator
, int start
, int length
)
48 this.itemName
= itemName
;
51 this.original_string
= original_string
;
53 // Transform and separator are never expanded for item refs
54 if (transform
!= null) {
55 this.transform
= new Expression ();
56 this.transform
.Parse (transform
, ParseOptions
.AllowMetadata
| ParseOptions
.Split
);
59 if (separator
!= null) {
60 this.separator
= new Expression ();
61 this.separator
.Parse (separator
, ParseOptions
.Split
);
65 // when evaluating property, allowItems=false, so,
66 // ItemRef will _not_ get created, so this wont get hit
67 // when evaluating items, expand: true
68 // other cases, expand: true
69 public string ConvertToString (Project project
, ExpressionOptions options
)
72 if (project
.TryGetEvaluatedItemByNameBatched (itemName
, out group))
73 return group.ConvertToString (transform
, separator
, options
);
78 public ITaskItem
[] ConvertToITaskItemArray (Project project
, ExpressionOptions options
)
81 if (project
.TryGetEvaluatedItemByNameBatched (itemName
, out group))
82 return group.ConvertToITaskItemArray (transform
, separator
, options
);
87 public string ItemName
{
88 get { return itemName; }
91 public Expression Transform
{
92 get { return transform; }
95 public Expression Separator
{
96 get { return separator; }
99 public string OriginalString
{
100 get { return original_string; }
104 get { return start; }
108 get { return start + length - 1; }
111 public override string ToString ()
113 return original_string
;