From dbd5999e389fa78e058cd3f78638508713ab8a2c Mon Sep 17 00:00:00 2001 From: Enrico Tirotta <33745977+EnricoTirotta@users.noreply.github.com> Date: Sun, 25 Feb 2018 09:41:08 +0100 Subject: [PATCH] Update Enumeration.cs --- .../Ordering.Domain/SeedWork/Enumeration.cs | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs index ecf248be9..ff261a61c 100644 --- a/src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs +++ b/src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs @@ -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 GetAll() 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().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); } }