Skip to content

Commit

Permalink
refactor: Simplfied ENumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jul 15, 2023
1 parent b34d0b3 commit 18b7a6a
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/LinkDotNet.Blog.Domain/Enumeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,14 @@ protected Enumeration(string key)
}

public static TEnumeration Create(string key)
{
var enumeration = All.SingleOrDefault(p => p.Key == key);

if (enumeration is null)
{
throw new InvalidOperationException($"{key} is not a valid value for {typeof(TEnumeration).Name}");
}

return enumeration;
}
=> All.SingleOrDefault(p => p.Key == key)
?? throw new InvalidOperationException($"{key} is not a valid value for {typeof(TEnumeration).Name}");

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

public override bool Equals(object obj)
{
if (obj is null)
{
return false;
}

if (obj.GetType() != typeof(TEnumeration))
if (obj?.GetType() != typeof(TEnumeration))
{
return false;
}
Expand Down

0 comments on commit 18b7a6a

Please sign in to comment.