Skip to content

Commit 18b7a6a

Browse files
committed
refactor: Simplfied ENumeration
1 parent b34d0b3 commit 18b7a6a

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

src/LinkDotNet.Blog.Domain/Enumeration.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,14 @@ protected Enumeration(string key)
3838
}
3939

4040
public static TEnumeration Create(string key)
41-
{
42-
var enumeration = All.SingleOrDefault(p => p.Key == key);
43-
44-
if (enumeration is null)
45-
{
46-
throw new InvalidOperationException($"{key} is not a valid value for {typeof(TEnumeration).Name}");
47-
}
48-
49-
return enumeration;
50-
}
41+
=> All.SingleOrDefault(p => p.Key == key)
42+
?? throw new InvalidOperationException($"{key} is not a valid value for {typeof(TEnumeration).Name}");
5143

5244
public override int GetHashCode() => Key.GetHashCode();
5345

5446
public override bool Equals(object obj)
5547
{
56-
if (obj is null)
57-
{
58-
return false;
59-
}
60-
61-
if (obj.GetType() != typeof(TEnumeration))
48+
if (obj?.GetType() != typeof(TEnumeration))
6249
{
6350
return false;
6451
}

0 commit comments

Comments
 (0)