File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
dotnet/src/webdriver/DevTools/Json Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 2626
2727namespace OpenQA . Selenium . DevTools . Json
2828{
29- internal class JsonEnumMemberConverter < TEnum > : JsonConverter < TEnum > where TEnum : Enum
29+ internal sealed class JsonEnumMemberConverter < TEnum > : JsonConverter < TEnum >
30+ where TEnum : struct , Enum
3031 {
3132 private readonly Dictionary < TEnum , string > _enumToString = new Dictionary < TEnum , string > ( ) ;
3233 private readonly Dictionary < string , TEnum > _stringToEnum = new Dictionary < string , TEnum > ( ) ;
3334
3435 public JsonEnumMemberConverter ( )
3536 {
3637 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
3943 foreach ( var value in values )
4044 {
41- var enumMember = type . GetMember ( value . ToString ( ) ) [ 0 ] ;
45+ var enumMember = type . GetField ( value . ToString ( ) ) ;
4246 var attr = enumMember . GetCustomAttributes ( typeof ( EnumMemberAttribute ) , false )
4347 . Cast < EnumMemberAttribute > ( )
4448 . FirstOrDefault ( ) ;
You can’t perform that action at this time.
0 commit comments