Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.FlagsAttribute no longer appears on any enum types #72

Closed
DefaultRyan opened this issue Dec 12, 2020 · 10 comments
Closed

System.FlagsAttribute no longer appears on any enum types #72

DefaultRyan opened this issue Dec 12, 2020 · 10 comments
Labels
usability Touch-up to improve the user experience for a language projection

Comments

@DefaultRyan
Copy link
Member

The old metadata used to put the flags attribute on enums like DXGI_ADAPTER_FLAG. Now the attribute no longer appears.

This attribute is used by projections to generate bitwise operators for these enums.

@kennykerr
Copy link
Contributor

I just put bitwise operators on any enums with an unsigned underlying type. No attribute needed. 😊

@AArnott
Copy link
Member

AArnott commented Dec 12, 2020

For .NET we definitely want the [Flags] attribute on those enums for which it makes sense. Analyzers light up based on the presence of that attribute and .NET itself offers some behaviors based on its presence. I think C# makes certain things easier too. Let's please bring it back.

@kennykerr
Copy link
Contributor

Naturally, you'll want the attribute for the C# projection but the metadata doesn't have to include it for you to generate it.

@AArnott
Copy link
Member

AArnott commented Dec 12, 2020

It does, because I can't assume that all enums should be treated as Flags. Surely some methods accept an enum where only one value should be specified, and the enums that define such values should not define a Flags attribute.

@kennykerr
Copy link
Contributor

I'd love to see such a concrete example. 😉

I'm not saying we shouldn't have an attribute - I'm just not sure it's necessary.

@AArnott
Copy link
Member

AArnott commented Dec 12, 2020

I'd love to see such a concrete example

Ok, here you go: padding schemes from bcrypt
in C# we use an enum without flags
which is consistent with the docs which describes BCRYPT_PADDING_SCHEMES as:

This data type is a DWORD. This can be one of the following values.

So yes, we certainly have cases where a parameter type can be just one.

Now I'm not sure if this particular case I found would actually be an enum in the header files or the metadata. But the ideal projection as defined by how a hand-written one would be, would define this as a non-Flags enum.

@kennykerr
Copy link
Contributor

Those aren't enums... 😏

By the way, Win32 enums that provide bitwise operators are identified by the DEFINE_ENUM_FLAG_OPERATORS macro (and the resulting operators it defines). If you want to generate the attribute - WHICH IS TOTALLY FINE BY ME 😉 - that's probably the best way to identify them from the source.

@AArnott
Copy link
Member

AArnott commented Dec 12, 2020

Thanks for the tip, @kennykerr. @sotteson1, can we bring back the attribute based on this hint?

@sotteson1
Copy link
Contributor

@AArnott - yes, any attributes that are flags should be marked appropriately. Since I can't get this automatically from the headers, we will need to add them manually to an input file (the system for this already exists). I'm not sure why it disappeared for DXGI_ADAPTER_FLAG or others but I'll look into it.

@AArnott AArnott added the usability Touch-up to improve the user experience for a language projection label Jan 14, 2021
@sotteson1
Copy link
Contributor

sotteson1 commented Mar 27, 2021

I'm adding Flags to DXGI_ADAPTER_FLAG and a couple others. I'm going to make the scraper look for DEFINE_ENUM_FLAG_OPERATORS to automatically get more of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability Touch-up to improve the user experience for a language projection
Projects
None yet
Development

No branches or pull requests

4 participants