You can use the extension method, but will it be much better?
Drop this on a static class:
public static bool IsOneOf(this ElementType self, params ElementType[] options)
{
return options.Contains(self);
}
And then you can do:
if (el.type.IsOneOf(ElementType.Type1, ElementType.Type2)) {
However, this will be much slower than your if statement, since there is an implicit array initialization followed by an array traversal, unlike (no more) two comparisons and branches.
source
share