forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckForDuplicateItemMetadata.cs
39 lines (32 loc) · 1.1 KB
/
CheckForDuplicateItemMetadata.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Build.Framework;
namespace Microsoft.NET.Build.Tasks
{
public class CheckForDuplicateItemMetadata : TaskBase
{
[Required]
public ITaskItem[] Items { get; set; }
[Required]
public string MetadataName { get; set; }
[Output]
public ITaskItem[] DuplicateItems { get; set; }
[Output]
public string[] DuplicatedMetadataValues { get; set; }
[Output]
public bool DuplicatesExist { get; set; }
protected override void ExecuteCore()
{
var groupings = Items.GroupBy(item => item.GetMetadata(MetadataName))
.Where(g => g.Count() > 1)
.ToList();
DuplicatesExist = groupings.Any();
DuplicatedMetadataValues = groupings
.Select(g => g.Key)
.ToArray();
DuplicateItems = groupings
.SelectMany(g => g)
.ToArray();
}
}
}