@@ -67,7 +67,8 @@ internal static bool AreValuesEqual(object value1, object value2, bool convertTy
6767 }
6868
6969 // If they are the same type but fail with Equals check, don't bother with conversion.
70- if ( value1 != null && value2 != null && value1 . GetType ( ) != value2 . GetType ( ) && convertType )
70+ if ( value1 is not null && value2 is not null && convertType
71+ && value1 . GetType ( ) != value2 . GetType ( ) )
7172 {
7273 // Try the conversion in both ways:
7374 return ConvertTypeEquals ( value1 , value2 ) || ConvertTypeEquals ( value2 , value1 ) ;
@@ -94,20 +95,13 @@ private static bool ConvertTypeEquals(object value1, object value2)
9495 private static object ConvertToEnum ( Type enumType , object value )
9596 {
9697 // value cannot be the same type of enum now
97- if ( value is string str )
98+ return value switch
9899 {
99- return Enum . TryParse ( enumType , str , out var e ) ? e : null ;
100- }
101-
102- if ( value is int || value is uint
103- || value is byte || value is sbyte
104- || value is long || value is ulong
105- || value is short || value is ushort )
106- {
107- return Enum . ToObject ( enumType , value ) ;
108- }
109-
110- return null ;
100+ string str => Enum . TryParse ( enumType , str , out var e ) ? e : null ,
101+ int or uint or byte or sbyte or long or ulong or short or ushort
102+ => Enum . ToObject ( enumType , value ) ,
103+ _ => null
104+ } ;
111105 }
112106 }
113107}
0 commit comments