I would like to pass an argument that says "all", "valid" or "invalid". Instead of going with a nullable bool, I thought that I'd give Flags
a shot.
Since I've never used it before, I would like you to sort a few questions out for me:
[Flags]
public enum Options
{
Valid,
Invalid
}
private void Foo(Options options)
{
Debug.WriteLine(string.Format("valid: {0} {1}",
(options & Options.Valid) == Options.Valid,
options.HasFlag(Options.Valid)));
Debug.WriteLine(string.Format("invalid: {0} {1}",
(options & Options.Invalid) == Options.Invalid,
options.HasFlag(Options.Invalid)));
Debug.WriteLine("---");
}
protected void Page_Load(object sender, EventArgs e)
{
Foo(Options.Valid | Options.Invalid);
Foo(Options.Invalid);
Foo(Options.Valid);
}
/*
Output:
valid: True True
invalid: True True
---
valid: True True
invalid: True True
---
valid: True True
invalid: False False
*/
As you can see, this doesn't give me the desired result. What I would like to know is if either "valid", "invalid" or both flags are set. How would I accomplish that?