11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4- using System ;
54using System . Collections . Generic ;
65
76namespace Microsoft . Build . Framework ;
@@ -41,11 +40,8 @@ string EvaluatedInclude
4140/// </remarks>
4241public readonly struct ItemData
4342{
44- private readonly Func < IEnumerable < KeyValuePair < string , string > > > _enumerateMetadata ;
45-
4643 public ItemData ( string type , object value )
4744 {
48-
4945 Type = type ;
5046 Value = value ;
5147
@@ -56,17 +52,14 @@ public ItemData(string type, object value)
5652 if ( value is IItemData dt )
5753 {
5854 EvaluatedInclude = dt . EvaluatedInclude ;
59- _enumerateMetadata = dt . EnumerateMetadata ;
6055 }
6156 else if ( value is ITaskItem ti )
6257 {
6358 EvaluatedInclude = ti . ItemSpec ;
64- _enumerateMetadata = ti . EnumerateMetadata ;
6559 }
6660 else
6761 {
6862 EvaluatedInclude = value . ToString ( ) ?? string . Empty ;
69- _enumerateMetadata = ( ) => [ ] ;
7063 }
7164 }
7265
@@ -91,5 +84,16 @@ public ItemData(string type, object value)
9184 /// The item metadata
9285 /// </summary>
9386 public IEnumerable < KeyValuePair < string , string > > EnumerateMetadata ( )
94- => _enumerateMetadata ( ) ;
87+ {
88+ if ( Value is IItemData dt )
89+ {
90+ return dt . EnumerateMetadata ( ) ;
91+ }
92+ else if ( Value is ITaskItem ti )
93+ {
94+ return ti . EnumerateMetadata ( ) ;
95+ }
96+
97+ return [ ] ;
98+ }
9599}
0 commit comments