Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • I tend to agree; and have generally taken to using enums in my new code if there's any vaguely chance that the conditions will be expanded in the future. Replacing a bool with an enum when something becomes a tri-state ends up creating really noisy diffs and making blaming code a lot more tedious; when you end up having to retrofit your code again a year down the road for a 3rd option. Commented Jan 19, 2016 at 19:33
  • 3
    I like the enum approach, but I'm not a huge fan of mixing Include and Exclude in the same enum as it's more difficult to grasp what's going on. If you want this to be truly extensible, you can make it a [Flags] enum, make them all IncludeXxx, and provide a IncludeAll which is set to Int32.MaxValue. Then you can provide 2 ReturnEmployeeIds overloads - one which returns all employees, and one which takes a WhatToInclude filter parameter which can be a combination of enum flags. Commented Jan 20, 2016 at 4:32
  • @LeopardSkinPillBoxHat Ok, I agree on the exclude/include. So this is a bit of contrived example, but I could have called it IncludeAllButManagement. On your other point, I don't agree - I think [Flags] is a relic and only should be used for legacy or performance reasons. I think a ISet<WhatToInclude> is a vastly better concept (unfortunately C# is lacking some syntactic sugar to make it nice to use). Commented Jan 20, 2016 at 9:23
  • @NiklasJ - I like the Flags approach because it allows the caller to pass WhatToInclude.Managers | WhatToInclude.Cleaners and the bitwise or expresses exactly how the caller will process it (i.e. managers or cleaners). Intuitive syntactic sugar :-) Commented Jan 20, 2016 at 9:35
  • @LeopardSkinPillBoxHat Exactly, but that's the only upside of that method. Downsides include for example limited number of choices and not being compatible with other linq-like concepts. Commented Jan 20, 2016 at 9:50