1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Linq ;
44using System . Reflection ;
@@ -11,20 +11,15 @@ public abstract class Enumeration : IComparable
1111
1212 public int Id { get ; private set ; }
1313
14- protected Enumeration ( )
15- {
16- }
14+ protected Enumeration ( ) { }
1715
1816 protected Enumeration ( int id , string name )
1917 {
2018 Id = id ;
2119 Name = name ;
2220 }
2321
24- public override string ToString ( )
25- {
26- return Name ;
27- }
22+ public override string ToString ( ) => Name ;
2823
2924 public static IEnumerable < T > GetAll < T > ( ) where T : Enumeration , new ( )
3025 {
@@ -37,9 +32,7 @@ public override string ToString()
3732 var locatedValue = info . GetValue ( instance ) as T ;
3833
3934 if ( locatedValue != null )
40- {
4135 yield return locatedValue ;
42- }
4336 }
4437 }
4538
@@ -48,20 +41,15 @@ public override bool Equals(object obj)
4841 var otherValue = obj as Enumeration ;
4942
5043 if ( otherValue == null )
51- {
5244 return false ;
53- }
5445
5546 var typeMatches = GetType ( ) . Equals ( obj . GetType ( ) ) ;
5647 var valueMatches = Id . Equals ( otherValue . Id ) ;
5748
5849 return typeMatches && valueMatches ;
5950 }
6051
61- public override int GetHashCode ( )
62- {
63- return Id . GetHashCode ( ) ;
64- }
52+ public override int GetHashCode ( ) => Id . GetHashCode ( ) ;
6553
6654 public static int AbsoluteDifference ( Enumeration firstValue , Enumeration secondValue )
6755 {
@@ -86,18 +74,11 @@ public static int AbsoluteDifference(Enumeration firstValue, Enumeration secondV
8674 var matchingItem = GetAll < T > ( ) . FirstOrDefault ( predicate ) ;
8775
8876 if ( matchingItem == null )
89- {
90- var message = string . Format ( "'{0}' is not a valid {1} in {2}" , value , description , typeof ( T ) ) ;
91-
92- throw new InvalidOperationException ( message ) ;
93- }
77+ throw new InvalidOperationException ( $ "'{ value } ' is not a valid { description } in { typeof ( T ) } ") ;
9478
9579 return matchingItem ;
9680 }
9781
98- public int CompareTo ( object other )
99- {
100- return Id . CompareTo ( ( ( Enumeration ) other ) . Id ) ;
101- }
82+ public int CompareTo ( object other ) => Id . CompareTo ( ( ( Enumeration ) other ) . Id ) ;
10283 }
10384}
0 commit comments