You can test for a specific value of your enum using a AND bitwise operation:
FxCopErrorCodes code = (FxCopErrorCodes)0x201;
if ((code & FxCopErrorCodes.InitializationError) == FxCopErrorCodes.InitializationError)
{
Console.WriteLine("InitializationError");
}
You could get the whole list of values using something like:
private static IEnumerable<FxCopErrorCodes> GetMatchingValues(FxCopErrorCodes enumValue)
{
// Special case for 0, as it always match using the bitwise AND operation
if (enumValue == 0)
{
yield return FxCopErrorCodes.NoErrors;
}
// Gets list of possible values for the enum
var values = Enum.GetValues(typeof(FxCopErrorCodes)).Cast<FxCopErrorCodes>();
// Iterates over values and return those that match
foreach (var value in values)
{
if (value > 0 && (enumValue & value) == value)
{
yield return value;
}
}
}