Browse Source

Merge pull request #523 from EnricoTirotta/patch-2

Update Enumeration.cs
pull/526/head
Miguel Veloso 7 years ago
committed by GitHub
parent
commit
963a39e2ac
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 25 deletions
  1. +6
    -25
      src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs

+ 6
- 25
src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs View File

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