Update Enumeration.cs
This commit is contained in:
parent
bc955e657b
commit
dbd5999e38
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@ -11,9 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
protected Enumeration()
|
||||
{
|
||||
}
|
||||
protected Enumeration(){}
|
||||
|
||||
protected Enumeration(int id, string name)
|
||||
{
|
||||
@ -21,10 +19,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
public override string ToString() => Name;
|
||||
|
||||
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;
|
||||
|
||||
if (locatedValue != null)
|
||||
{
|
||||
yield return locatedValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,9 +41,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
||||
var otherValue = obj as Enumeration;
|
||||
|
||||
if (otherValue == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var typeMatches = GetType().Equals(obj.GetType());
|
||||
var valueMatches = Id.Equals(otherValue.Id);
|
||||
@ -58,10 +49,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
||||
return typeMatches && valueMatches;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
public override int GetHashCode() => Id.GetHashCode();
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public int CompareTo(object other)
|
||||
{
|
||||
return Id.CompareTo(((Enumeration)other).Id);
|
||||
}
|
||||
public int CompareTo(object other) => Id.CompareTo(((Enumeration) other).Id);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user