Skip to content

Commit 46dd920

Browse files
committed
Fix Trim analysis warning IL2075: Elastic.Transport.Extensions.EnumExtensions.GetEnumName(Enum)
1 parent 143ef3b commit 46dd920

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

examples/transport-aot-example/transport-aot-example.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Nullable>enable</Nullable>
99
<PublishAot>true</PublishAot>
1010
<TrimmerSingleWarn>false</TrimmerSingleWarn>
11+
<WarningsAsErrors>true</WarningsAsErrors>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

src/Elastic.Transport/Extensions/Extensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics.CodeAnalysis;
78
using System.Globalization;
89
using System.IO;
910
using System.Linq;
@@ -14,9 +15,10 @@ namespace Elastic.Transport.Extensions;
1415

1516
internal static class EnumExtensions
1617
{
17-
public static string GetEnumName(this Enum e)
18+
public static string GetEnumName<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]T>(this T e)
19+
where T : Enum
1820
{
19-
var attributes = e.GetType().GetField(e.ToString())?.GetCustomAttributes(typeof(EnumMemberAttribute), false);
21+
var attributes = typeof(T).GetField(e.ToString())?.GetCustomAttributes(typeof(EnumMemberAttribute), false);
2022
if (attributes is null || attributes.Length == 0)
2123
return e.ToString();
2224

0 commit comments

Comments
 (0)