Browse Source

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>
pull/1646/head
Matt Callahan 3 years ago
committed by GitHub
parent
commit
a71b004897
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 19 deletions
  1. +3
    -3
      src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs
  2. +12
    -16
      src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs

+ 3
- 3
src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs View File

@ -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)


+ 12
- 16
src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs View File

@ -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…
Cancel
Save