@@ -60,10 +60,11 @@ public static IReadOnlyList<TEnum> Values
6060 internal static ConcurrentDictionary < TEnum , IReadOnlyList < Attribute > > Attributes
6161 => LazyInitializer . EnsureInitialized ( ref _attributes ) ! ;
6262
63- static Func < TEnum , string > GetEnumNameDelegate ( )
63+ private static Func < TEnum , string > GetEnumNameDelegate ( )
6464 {
65- var tResult = typeof ( string ) ;
66- var eValue = Parameter ( typeof ( TEnum ) , "value" ) ; // (TEnum value)
65+ Type tResult = typeof ( string ) ;
66+ ParameterExpression eValue
67+ = Parameter ( typeof ( TEnum ) , "value" ) ; // (TEnum value)
6768
6869 return Lambda < Func < TEnum , string > > (
6970 Switch ( tResult , eValue ,
@@ -85,12 +86,12 @@ internal static Func<TEnum, string> NameLookup
8586 GetEnumNameDelegate ) ! ;
8687 internal static Func < string , ValueLookupResult > GetEnumTryParseDelegate ( )
8788 {
88- var valueParam = Parameter ( typeof ( string ) , "value" ) ;
89- var lengthParam = Variable ( typeof ( int ) , "length" ) ;
90- var defaultExpression = CreateNewTuple ( false , default ! ) ;
91- var enumValues = Values . Select ( v => ( value : v , name : string . Intern ( v . ToString ( ) ) ) ) ;
92- var nameGroups = enumValues . GroupBy ( v => v . name . Length ) . OrderBy ( g => g . Key ) ;
93- var lengthCheckCases = nameGroups . Select ( group =>
89+ ParameterExpression valueParam = Parameter ( typeof ( string ) , "value" ) ;
90+ ParameterExpression lengthParam = Variable ( typeof ( int ) , "length" ) ;
91+ Expression defaultExpression = CreateNewTuple ( false , default ! ) ;
92+ IEnumerable < ( TEnum value , string name ) > enumValues = Values . Select ( v => ( value : v , name : string . Intern ( v . ToString ( ) ) ) ) ;
93+ IOrderedEnumerable < IGrouping < int , ( TEnum value , string name ) > > nameGroups = enumValues . GroupBy ( v => v . name . Length ) . OrderBy ( g => g . Key ) ;
94+ SwitchCase [ ] lengthCheckCases = nameGroups . Select ( group =>
9495 SwitchCase (
9596 Switch (
9697 valueParam ,
@@ -150,31 +151,32 @@ internal static IReadOnlyDictionary<string, TEnum> IgnoreCaseLookup
150151 {
151152 // If the enum has duplicate values, we want to use the first one.
152153 var result = new Dictionary < string , TEnum > ( StringComparer . OrdinalIgnoreCase ) ;
153- foreach ( var e in Values )
154+ foreach ( TEnum e in Values )
154155 {
155- var v = Enum . GetName ( typeof ( TEnum ) , e ) ! ;
156+ string v = Enum . GetName ( typeof ( TEnum ) , e ) ! ;
156157 if ( result . ContainsKey ( v ) ) continue ;
157158 result [ v ] = e ;
158159 }
160+
159161 return result ;
160162 } ) ! ;
161163
162- static Entry [ ] ? [ ] CreateLookup ( )
164+ private static Entry [ ] ? [ ] CreateLookup ( )
163165 {
164- var longest = 0 ;
166+ int longest = 0 ;
165167 var d = new Dictionary < int , List < Entry > > ( ) ;
166168
167- foreach ( var e in Values )
169+ foreach ( TEnum e in Values )
168170 {
169- var n = string . Intern ( e . ToString ( ) ) ;
170- var len = n . Length ;
171+ string n = string . Intern ( e . ToString ( ) ) ;
172+ int len = n . Length ;
171173 if ( len > longest ) longest = len ;
172- if ( ! d . TryGetValue ( len , out var v ) ) d . Add ( len , v = [ ] ) ;
174+ if ( ! d . TryGetValue ( len , out List < Entry > ? v ) ) d . Add ( len , v = [ ] ) ;
173175 v . Add ( new ( n , e ) ) ;
174176 }
175177
176178 var result = new Entry [ ] ? [ longest + 1 ] ;
177- foreach ( var i in d . Keys )
179+ foreach ( int i in d . Keys )
178180 result [ i ] = [ .. d [ i ] . OrderBy ( v => v . Name ) ] ;
179181
180182 return result ;
@@ -194,10 +196,10 @@ public Entry(string name, TEnum value)
194196 public static int Find ( Span < Entry > span , ReadOnlySpan < char > name , StringComparison sc )
195197 {
196198 // Small enough? Just brute force the index.
197- var len = span . Length ;
199+ int len = span . Length ;
198200 if ( len < 12 )
199201 {
200- for ( var i = 0 ; i < len ; i ++ )
202+ for ( int i = 0 ; i < len ; i ++ )
201203 {
202204 ref Entry e = ref span [ i ] ;
203205 if ( name . Equals ( e . Name , sc ) )
@@ -214,12 +216,12 @@ public static int Find(Span<Entry> span, ReadOnlySpan<char> name, StringComparis
214216 while ( left <= right )
215217 {
216218 int middle = left + ( right - left ) / 2 ;
217- var middleKey = span [ middle ] . Name . AsSpan ( ) ;
219+ ReadOnlySpan < char > middleKey = span [ middle ] . Name . AsSpan ( ) ;
218220
219221 if ( right - left < 4 && name . Equals ( middleKey , sc ) )
220222 return middle ;
221223
222- var comparison = name . CompareTo ( middleKey , sc ) ;
224+ int comparison = name . CompareTo ( middleKey , sc ) ;
223225 if ( comparison < 0 )
224226 right = middle - 1 ;
225227 else if ( comparison > 0 )
@@ -326,7 +328,7 @@ public override bool Equals(object? obj)
326328 /// </summary>
327329 public static implicit operator EnumValue < TEnum > ( string value ) => new ( value ) ;
328330
329- static class Underlying < T >
331+ private static class Underlying < T >
330332 where T : notnull
331333 {
332334 public static readonly Dictionary < T , TEnum > Map = [ ] ;
@@ -336,7 +338,7 @@ static Underlying()
336338 {
337339 if ( typeof ( T ) != UnderlyingType ) return ;
338340
339- foreach ( var e in Values )
341+ foreach ( TEnum e in Values )
340342 {
341343 var i = ( T ) System . Convert . ChangeType ( e , typeof ( T ) ) ;
342344 Map . Add ( i , e ) ;
@@ -361,7 +363,7 @@ public static bool TryGetValue<T>(T value, out TEnum e)
361363
362364 private string GetDebuggerDisplay ( )
363365 {
364- var eType = typeof ( TEnum ) ;
366+ Type eType = typeof ( TEnum ) ;
365367 return $ "{ eType . Name } .{ Value } [EnumValue<{ eType . FullName } >]";
366368 }
367369}
@@ -481,7 +483,7 @@ public static implicit operator EnumValueCaseIgnored<TEnum>(string value)
481483
482484 private string GetDebuggerDisplay ( )
483485 {
484- var eType = typeof ( TEnum ) ;
486+ Type eType = typeof ( TEnum ) ;
485487 return $ "{ eType . Name } .{ ToString ( ) } [EnumValueCaseIgnored<{ eType . FullName } >]";
486488 }
487489}
@@ -501,7 +503,7 @@ public static class EnumValue
501503 public static TEnum Parse < TEnum > ( string value )
502504 where TEnum : notnull , Enum
503505 {
504- var ( success , result ) = EnumValue < TEnum > . ValueLookup ( value ) ;
506+ ( bool success , TEnum result ) = EnumValue < TEnum > . ValueLookup ( value ) ;
505507 return success ? result
506508 : throw new ArgumentException ( string . Format ( NotFoundMessage , value ) , nameof ( value ) ) ;
507509 }
@@ -511,7 +513,7 @@ public static TEnum Parse<TEnum>(string value)
511513 public static bool TryParse < TEnum > ( string value , out TEnum e )
512514 where TEnum : notnull , Enum
513515 {
514- var result = EnumValue < TEnum > . ValueLookup ( value ) ;
516+ EnumValue < TEnum > . ValueLookupResult result = EnumValue < TEnum > . ValueLookup ( value ) ;
515517 e = result . Value ;
516518 return result . Success ;
517519 }
@@ -523,15 +525,15 @@ public static bool TryParse<TEnum>(string value, out TEnum e)
523525 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
524526 public static TEnum Parse < TEnum > ( StringSegment value )
525527 where TEnum : notnull , Enum
526- => TryParse < TEnum > ( value , false , out var e ) ? e
528+ => TryParse < TEnum > ( value , false , out TEnum ? e ) ? e
527529 : throw new ArgumentException ( string . Format ( NotFoundMessage , value ) , nameof ( value ) ) ;
528530
529531 /// <inheritdoc cref="TryParse{TEnum}(StringSegment, bool, out TEnum)"/>
530532 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
531533 public static TEnum Parse < TEnum > ( string value , bool ignoreCase )
532534 where TEnum : notnull , Enum
533535 => ignoreCase
534- ? EnumValue < TEnum > . IgnoreCaseLookup . TryGetValue ( value , out var e ) ? e
536+ ? EnumValue < TEnum > . IgnoreCaseLookup . TryGetValue ( value , out TEnum ? e ) ? e
535537 : throw new ArgumentException ( string . Format ( NotFoundMessage , value ) , nameof ( value ) )
536538 : Parse < TEnum > ( value ) ;
537539
@@ -540,10 +542,10 @@ public static TEnum Parse<TEnum>(string value, bool ignoreCase)
540542 public static TEnum Parse < TEnum > ( StringSegment value , bool ignoreCase )
541543 where TEnum : notnull , Enum
542544 {
543- var buffer = value . Buffer ?? throw new ArgumentNullException ( nameof ( value ) ) ;
545+ string buffer = value . Buffer ?? throw new ArgumentNullException ( nameof ( value ) ) ;
544546 return value . Length == buffer . Length
545547 ? Parse < TEnum > ( value . Buffer , ignoreCase )
546- : TryParse < TEnum > ( value , ignoreCase , out var e )
548+ : TryParse < TEnum > ( value , ignoreCase , out TEnum ? e )
547549 ? e : throw new ArgumentException ( string . Format ( NotFoundMessage , value ) , nameof ( value ) ) ;
548550 }
549551
@@ -578,27 +580,27 @@ public static bool TryParseIgnoreCase<TEnum>(string name, out TEnum e)
578580 public static bool TryParse < TEnum > ( StringSegment name , bool ignoreCase , out TEnum e )
579581 where TEnum : notnull , Enum
580582 {
581- var len = name . Length ;
583+ int len = name . Length ;
582584 if ( len == 0 ) goto notFound ;
583585
584586 // If this is a string, use the optimized version.
585587 string buffer = name . Buffer ! ;
586588 if ( buffer . Length == len )
587589 return TryParse ( buffer , ignoreCase , out e ) ;
588590
589- var lookup = EnumValue < TEnum > . Lookup ;
591+ EnumValue < TEnum > . Entry [ ] ? [ ] lookup = EnumValue < TEnum > . Lookup ;
590592 if ( len >= lookup . Length ) goto notFound ;
591593
592- var r = lookup [ len ] ;
594+ EnumValue < TEnum > . Entry [ ] ? r = lookup [ len ] ;
593595 if ( r is null ) goto notFound ;
594596 Debug . Assert ( r . Length != 0 ) ;
595597
596- var sc = ignoreCase
598+ StringComparison sc = ignoreCase
597599 ? StringComparison . OrdinalIgnoreCase
598600 : StringComparison . Ordinal ;
599601
600- var span = r . AsSpan ( ) ;
601- var index = EnumValue < TEnum > . Entry . Find ( span , name , sc ) ;
602+ Span < EnumValue < TEnum > . Entry > span = r . AsSpan ( ) ;
603+ int index = EnumValue < TEnum > . Entry . Find ( span , name , sc ) ;
602604 if ( index != - 1 )
603605 {
604606 e = span [ index ] . Value ;
@@ -641,8 +643,8 @@ public static IReadOnlyList<Attribute> GetAttributes<TEnum>(this TEnum value)
641643
642644 static IReadOnlyList < Attribute > GetAttributesCore ( TEnum value )
643645 {
644- var memInfo = typeof ( TEnum ) . GetMember ( value . GetName ( ) ) ;
645- var attributes = memInfo [ 0 ] . GetCustomAttributes ( false ) ;
646+ MemberInfo [ ] memInfo = typeof ( TEnum ) . GetMember ( value . GetName ( ) ) ;
647+ object [ ] attributes = memInfo [ 0 ] . GetCustomAttributes ( false ) ;
646648 return attributes . Length is 0
647649 ? Array . Empty < Attribute > ( )
648650 : Array . AsReadOnly ( attributes . OfType < Attribute > ( ) . ToArray ( ) ) ;
0 commit comments