Skip to content

Commit 880b5bd

Browse files
AOT compatible: NuGet.LibraryModel (#7140)
1 parent 74ea66a commit 880b5bd

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace NuGet.LibraryModel
7+
{
8+
internal class EnumUtility
9+
{
10+
public static TEnum[] GetValues<TEnum>() where TEnum : struct, Enum =>
11+
#if NET
12+
Enum.GetValues<TEnum>();
13+
#else
14+
(TEnum[])Enum.GetValues(typeof(TEnum));
15+
#endif
16+
}
17+
}

src/NuGet.Core/NuGet.LibraryModel/LibraryDependencyTargetUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static string GetFlagString(LibraryDependencyTarget flags)
125125

126126
var flagStrings = new List<string>();
127127

128-
foreach (LibraryDependencyTarget value in Enum.GetValues(typeof(LibraryDependencyTarget)))
128+
foreach (LibraryDependencyTarget value in EnumUtility.GetValues<LibraryDependencyTarget>())
129129
{
130130
if (value != LibraryDependencyTarget.None && flags.HasFlag(value))
131131
{

src/NuGet.Core/NuGet.LibraryModel/LibraryIncludeFlagUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static string GetFlagString(LibraryIncludeFlags flags)
8686

8787
var flagStrings = new List<string>();
8888

89-
foreach (LibraryIncludeFlags value in Enum.GetValues(typeof(LibraryIncludeFlags)))
89+
foreach (LibraryIncludeFlags value in EnumUtility.GetValues<LibraryIncludeFlags>())
9090
{
9191
if (value != LibraryIncludeFlags.None && flags.HasFlag(value))
9292
{

src/NuGet.Core/NuGet.LibraryModel/NuGet.LibraryModel.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<Shipping>true</Shipping>
88
<IncludeInVSIX>true</IncludeInVSIX>
99
<XPLATProject>true</XPLATProject>
10+
<IsAotCompatible>true</IsAotCompatible>
1011
<Description>NuGet's types and interfaces for understanding dependencies.</Description>
1112
</PropertyGroup>
1213

0 commit comments

Comments
 (0)