using System;
namespace SCMA
{
public static class EnumerationExtensions
{
///
/// checks if the value contains the provided type
///
///
///
///
///
public static bool Has(this System.Enum type, T value)
{
try
{
return (((int)(object)type & (int)(object)value) == (int)(object)value);
}
catch
{
return false;
}
}
///
/// checks if the value is only the provided type
///
///
///
///
///
public static bool Is(this System.Enum type, T value)
{
try
{
return (int)(object)type == (int)(object)value;
}
catch
{
return false;
}
}
///
/// appends a value
///
///
///
///
///
public static T Add(this System.Enum type, T value)
{
try
{
return (T)(object)(((int)(object)type | (int)(object)value));
}
catch (Exception ex)
{
throw new ArgumentException(
string.Format(
"Could not append value from enumerated type '{0}'.",
typeof(T).Name
), ex);
}
}
///
/// completely removes the value
///
///
///
///
///
public static T Remove(this System.Enum type, T value)
{
try
{
return (T)(object)(((int)(object)type & ~(int)(object)value));
}
catch (Exception ex)
{
throw new ArgumentException(
string.Format(
"Could not remove value from enumerated type '{0}'.",
typeof(T).Name
), ex);
}
}
}
}