forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileGroup.cs
91 lines (74 loc) · 3.05 KB
/
FileGroup.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using NuGet.ProjectModel;
namespace Microsoft.NET.Build.Tasks
{
using PathAndPropertiesTuple = Tuple<string, IDictionary<string, string>>;
/// <summary>
/// Values for File Group Metadata corresponding to the groups in a target library
/// </summary>
internal enum FileGroup
{
CompileTimeAssembly,
RuntimeAssembly,
ContentFile,
NativeLibrary,
ResourceAssembly,
RuntimeTarget,
FrameworkAssembly
}
internal static class FileGroupExtensions
{
private static readonly IDictionary<string, string> _emptyProperties = new Dictionary<string, string>();
/// <summary>
/// Return Type metadata that should be applied to files in the target library group
/// </summary>
public static string GetTypeMetadata(this FileGroup fileGroup)
{
switch (fileGroup)
{
case FileGroup.CompileTimeAssembly:
case FileGroup.RuntimeAssembly:
case FileGroup.NativeLibrary:
case FileGroup.ResourceAssembly:
case FileGroup.RuntimeTarget:
return "assembly";
case FileGroup.FrameworkAssembly:
return "frameworkAssembly";
case FileGroup.ContentFile:
return "content";
default:
return null;
}
}
/// <summary>
/// Return a list of file paths from the corresponding group in the target library
/// </summary>
public static IEnumerable<PathAndPropertiesTuple> GetFilePathAndProperties(
this FileGroup fileGroup, LockFileTargetLibrary package)
{
switch (fileGroup)
{
case FileGroup.CompileTimeAssembly:
return SelectPath(package.CompileTimeAssemblies);
case FileGroup.RuntimeAssembly:
return SelectPath(package.RuntimeAssemblies);
case FileGroup.ContentFile:
return SelectPath(package.ContentFiles);
case FileGroup.NativeLibrary:
return SelectPath(package.NativeLibraries);
case FileGroup.ResourceAssembly:
return SelectPath(package.ResourceAssemblies);
case FileGroup.RuntimeTarget:
return SelectPath(package.RuntimeTargets);
case FileGroup.FrameworkAssembly:
return package.FrameworkAssemblies.Select(c => Tuple.Create(c, _emptyProperties));
default:
throw new ArgumentOutOfRangeException(nameof(fileGroup));
}
}
private static IEnumerable<PathAndPropertiesTuple> SelectPath<T>(IList<T> fileItemList)
where T : LockFileItem
=> fileItemList.Select(c => Tuple.Create(c.Path, c.Properties));
}
}