updated CardType and Enumeration classes (#1528)
* updated CardType and Enumeration classes * Update per IEvangelist's suggestion * Update src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs Co-authored-by: David Pine <david.pine@microsoft.com> Co-authored-by: Sumit Ghosh <sumit.ghosh@neudesic.com> Co-authored-by: David Pine <david.pine@microsoft.com>
This commit is contained in:
parent
5974647b52
commit
a71b004897
@ -9,9 +9,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
||||
public class CardType
|
||||
: Enumeration
|
||||
{
|
||||
public static CardType Amex = new CardType(1, "Amex");
|
||||
public static CardType Visa = new CardType(2, "Visa");
|
||||
public static CardType MasterCard = new CardType(3, "MasterCard");
|
||||
public static CardType Amex = new CardType(1, nameof(Amex));
|
||||
public static CardType Visa = new CardType(2, nameof(Visa));
|
||||
public static CardType MasterCard = new CardType(3, nameof(MasterCard));
|
||||
|
||||
public CardType(int id, string name)
|
||||
: base(id, name)
|
||||
|
@ -11,27 +11,23 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
protected Enumeration(int id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
protected Enumeration(int id, string name) => (Id, Name) = (id, name);
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
public static IEnumerable<T> GetAll<T>() where T : Enumeration
|
||||
{
|
||||
var fields = typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
|
||||
|
||||
return fields.Select(f => f.GetValue(null)).Cast<T>();
|
||||
}
|
||||
|
||||
|
||||
public static IEnumerable<T> GetAll<T>() where T : Enumeration =>
|
||||
typeof(T).GetFields(BindingFlags.Public |
|
||||
BindingFlags.Static |
|
||||
BindingFlags.DeclaredOnly)
|
||||
.Select(f => f.GetValue(null))
|
||||
.Cast<T>();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var otherValue = obj as Enumeration;
|
||||
|
||||
if (otherValue == null)
|
||||
if (obj is not Enumeration otherValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var typeMatches = GetType().Equals(obj.GetType());
|
||||
var valueMatches = Id.Equals(otherValue.Id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user