Removed redundant code from CheckHasValue and used IsValid

pull/83/head
David Hall 2019-07-23 13:52:32 -06:00
parent b953ab02f4
commit 277bddcf58
1 changed files with 2 additions and 11 deletions

View File

@ -31,17 +31,8 @@ namespace Vanara.Extensions
/// <exception cref="InvalidEnumArgumentException"></exception>
public static void CheckHasValue<T>(T value, string argName = null) where T : struct, System.Enum
{
if (IsFlags<T>())
{
var allFlags = 0L;
foreach (T flag in Enum.GetValues(typeof(T)))
allFlags |= Convert.ToInt64(flag);
if ((allFlags & Convert.ToInt64(value)) != 0L)
return;
}
else if (Enum.IsDefined(typeof(T), value))
return;
throw new InvalidEnumArgumentException(argName ?? "value", Convert.ToInt32(value), typeof(T));
if (!IsValid(value))
throw new InvalidEnumArgumentException(argName ?? "value", Convert.ToInt32(value), typeof(T));
}
/// <summary>Clears the specified flags from an enumerated value and returns the new value.</summary>