ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

IsSet

I did not write this I just found it very useful, check http://stackoverflow.com/questions/7244 for original post.

Source

public static bool IsSet(this Enum input, Enum matchTo)
{
    return (Convert.ToUInt32(input) & Convert.ToUInt32(matchTo)) != 0;
}

Example

MyEnum tester = MyEnum.FlagA | MyEnum.FlagB;

if(tester.IsSet(MyEnum.FlagA))

Author: JA

Submitted on: 8 sep. 2009

Language: C#

Type: System.Enum

Views: 7885