次の列挙を検討してください。
[System.Flags]
public enum EnumType: int
{
None = 0,
Black = 2,
White = 4,
Both = Black | White,
Either = ???, // How would you do this?
}
現在、私は拡張メソッドを書いています:
public static bool IsEither (this EnumType type)
{
return
(
((type & EnumType.Major) == EnumType.Major)
|| ((type & EnumType.Minor) == EnumType.Minor)
);
}
これを達成するためのよりエレガントな方法はありますか?
更新:回答から明らかなように、 EnumType.Either は列挙型自体の中に場所がありません。