Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Noren11576yThe frontend cant handle flags, a list of used enums is simpler. So i built an extension for easy converting.
-
@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. -
Why can't front end handle flags? Js also supports bitwise operations. And c# does support bitwise operations on enums.
-
gruff5526yAn 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
-
Noren11576yCurrently 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 :)
Related Rants
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 😊
rant
c#