21
Noren
6y

In C# you are not able to do bitwise operations on generic enums so you have to cast them to an integer via object... 😐 Apart from that, this awesome code shows what C# can do 😊

Comments
  • 1
    The frontend cant handle flags, a list of used enums is simpler. So i built an extension for easy converting.
  • 1
    @davenall The point of methods of course is that you don't have to understand the snippet inside. I think the signature of the first method is reasonable, and if the name of the second method was something more descriptive, like GetFlags, AsSeparateFlags or ToFlagList, then the call site should read perfectly fine and unambiguous.

    That the method body is somewhat ugly is then nicely factored away. However, I think the (int)(object) parts aren't terrible: in generic code that sometimes happens. Moreover, in a code review I'd primarily ask why it builds a list rather than yielding intermediate results.
  • 0
    Why can't front end handle flags? Js also supports bitwise operations. And c# does support bitwise operations on enums.
  • 0
    An enumeration is an int so you can do (YourEnum) 3 if that enum is implemented [HasFlags] enum { logging = 1, testing = 2 } then YourEnum.HasFlag(YourEnum.logging) and YourEnum.HasFlag(YourEnum.testing) will both be true for the int 3
  • 0
    Currently im not at the frontend, either an integer list or a enum list with integer values is accepted. @JBSnorro I noticed it myself and used yield return but you caught me giving names. Im a bit lazy there :)
  • 0
    omfg, can you take screenshots instead of taking photos dog gamnit
  • 1
    @Flame239 On my corporate computer? Then posting to devrant? Im not that crazy.
Add Comment