Generic extension method to see if an enum contains a flag

前端 未结 8 1096
闹比i
闹比i 2021-02-01 01:56

Considering this:

[Flags]
public enum MyEnum {
    One = 1,
    Two = 2,
    Four = 4,
    Eight = 8
}

public static class FlagsHelper
{
    public static bool          


        
8条回答
  •  孤独总比滥情好
    2021-02-01 02:45

    This is an example of something that should work.

    public static bool IsValid(this T value)
    {
        return Enum.IsDefined(value.GetType(), value);
    }
    

提交回复
热议问题