|
@ -1,4 +1,4 @@ |
|
|
using System; |
|
|
|
|
|
|
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Reflection; |
|
|
using System.Reflection; |
|
@ -11,9 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork |
|
|
|
|
|
|
|
|
public int Id { get; private set; } |
|
|
public int Id { get; private set; } |
|
|
|
|
|
|
|
|
protected Enumeration() |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected Enumeration(){} |
|
|
|
|
|
|
|
|
protected Enumeration(int id, string name) |
|
|
protected Enumeration(int id, string name) |
|
|
{ |
|
|
{ |
|
@ -21,10 +19,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork |
|
|
Name = name; |
|
|
Name = name; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
|
|
{ |
|
|
|
|
|
return Name; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public override string ToString() => Name; |
|
|
|
|
|
|
|
|
public static IEnumerable<T> GetAll<T>() where T : Enumeration, new() |
|
|
public static IEnumerable<T> GetAll<T>() where T : Enumeration, new() |
|
|
{ |
|
|
{ |
|
@ -37,9 +32,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork |
|
|
var locatedValue = info.GetValue(instance) as T; |
|
|
var locatedValue = info.GetValue(instance) as T; |
|
|
|
|
|
|
|
|
if (locatedValue != null) |
|
|
if (locatedValue != null) |
|
|
{ |
|
|
|
|
|
yield return locatedValue; |
|
|
yield return locatedValue; |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -48,9 +41,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork |
|
|
var otherValue = obj as Enumeration; |
|
|
var otherValue = obj as Enumeration; |
|
|
|
|
|
|
|
|
if (otherValue == null) |
|
|
if (otherValue == null) |
|
|
{ |
|
|
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var typeMatches = GetType().Equals(obj.GetType()); |
|
|
var typeMatches = GetType().Equals(obj.GetType()); |
|
|
var valueMatches = Id.Equals(otherValue.Id); |
|
|
var valueMatches = Id.Equals(otherValue.Id); |
|
@ -58,10 +49,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork |
|
|
return typeMatches && valueMatches; |
|
|
return typeMatches && valueMatches; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override int GetHashCode() |
|
|
|
|
|
{ |
|
|
|
|
|
return Id.GetHashCode(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public override int GetHashCode() => Id.GetHashCode(); |
|
|
|
|
|
|
|
|
public static int AbsoluteDifference(Enumeration firstValue, Enumeration secondValue) |
|
|
public static int AbsoluteDifference(Enumeration firstValue, Enumeration secondValue) |
|
|
{ |
|
|
{ |
|
@ -86,18 +74,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork |
|
|
var matchingItem = GetAll<T>().FirstOrDefault(predicate); |
|
|
var matchingItem = GetAll<T>().FirstOrDefault(predicate); |
|
|
|
|
|
|
|
|
if (matchingItem == null) |
|
|
if (matchingItem == null) |
|
|
{ |
|
|
|
|
|
var message = string.Format("'{0}' is not a valid {1} in {2}", value, description, typeof(T)); |
|
|
|
|
|
|
|
|
|
|
|
throw new InvalidOperationException(message); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
throw new InvalidOperationException($"'{value}' is not a valid {description} in {typeof(T)}"); |
|
|
|
|
|
|
|
|
return matchingItem; |
|
|
return matchingItem; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int CompareTo(object other) |
|
|
|
|
|
{ |
|
|
|
|
|
return Id.CompareTo(((Enumeration)other).Id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public int CompareTo(object other) => Id.CompareTo(((Enumeration) other).Id); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |