File tree 1 file changed +8
-4
lines changed
dotnet/src/webdriver/DevTools/Json
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 26
26
27
27
namespace OpenQA . Selenium . DevTools . Json
28
28
{
29
- internal class JsonEnumMemberConverter < TEnum > : JsonConverter < TEnum > where TEnum : Enum
29
+ internal sealed class JsonEnumMemberConverter < TEnum > : JsonConverter < TEnum >
30
+ where TEnum : struct , Enum
30
31
{
31
32
private readonly Dictionary < TEnum , string > _enumToString = new Dictionary < TEnum , string > ( ) ;
32
33
private readonly Dictionary < string , TEnum > _stringToEnum = new Dictionary < string , TEnum > ( ) ;
33
34
34
35
public JsonEnumMemberConverter ( )
35
36
{
36
37
var type = typeof ( TEnum ) ;
37
- var values = Enum . GetValues ( type ) ;
38
-
38
+ #if NET8_0_OR_GREATER
39
+ TEnum [ ] values = Enum . GetValues < TEnum > ( ) ;
40
+ #else
41
+ Array values = Enum . GetValues ( type ) ;
42
+ #endif
39
43
foreach ( var value in values )
40
44
{
41
- var enumMember = type . GetMember ( value . ToString ( ) ) [ 0 ] ;
45
+ var enumMember = type . GetField ( value . ToString ( ) ) ;
42
46
var attr = enumMember . GetCustomAttributes ( typeof ( EnumMemberAttribute ) , false )
43
47
. Cast < EnumMemberAttribute > ( )
44
48
. FirstOrDefault ( ) ;
You can’t perform that action at this time.
0 commit comments