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

Use System.IO.SeekOrigin instead of System.Com.STREAM_SEEK #675

Closed
elachlan opened this issue Aug 27, 2022 · 5 comments · Fixed by #686
Closed

Use System.IO.SeekOrigin instead of System.Com.STREAM_SEEK #675

elachlan opened this issue Aug 27, 2022 · 5 comments · Fixed by #686
Assignees
Labels
enhancement New feature or request

Comments

@elachlan
Copy link
Contributor

elachlan commented Aug 27, 2022

The values match between them.

We need something like BclInteropStructs in the Generator for BCL enums. Allowing us to replace a generated enum with an enum from the BCL.

@elachlan elachlan added the enhancement New feature or request label Aug 27, 2022
@AArnott AArnott added good first issue Good for newcomers help wanted Extra attention is needed labels Aug 28, 2022
@AArnott
Copy link
Member

AArnott commented Aug 28, 2022

Sounds good. Thanks for confirming that the values are the same. Are you calling out that the BclInteropStructs support we already have for substituting metadata types with BCL types doesn't yet work for enums? If so, that's something I'd support improving.

But in this case, I wonder... what is the benefit of sharing an enum here? The cost is that the enum type used won't match win32 documentation. With structs this cost is often outweighed by the improved interoperability with other BCL-based code. But for a STREAM_SEEK enum, is there material benefit? Will there ever be code that is given one type and must use the other type?

I'm not against consolidating these two types, ... but if there's no know benefit, I'm on the fence.

@elachlan
Copy link
Contributor Author

Winforms uses the BCL enum on its IStream interface and that is what inspired this issue.

IF we replace it, it will be used everywhere and so that concern won't matter for code we generate. Even if a user passes the enum to external win32 code it shouldn't be a problem because the underlying type of the enum is the same.

I can see how the docs could be an issue.

There would be marginally less generated code and its not hard to cast between the enums. So the benefit isn't massive.

@AArnott
Copy link
Member

AArnott commented Aug 29, 2022

Thanks. I'm still on the fence but I'd accept a PR for this.

@elachlan
Copy link
Contributor Author

Do we have a policy on using BCL structs/enums? I know we use a few BCL structs where it directly mirrors win32api (blittable).

@AArnott
Copy link
Member

AArnott commented Aug 30, 2022

This is what I'd suggest as a policy:
For structs, we want to reuse them where they are compatible. Enums may be shared when all members are equivalent as well, particularly when:

  • the enum values are not likely to change over time, since if they did, the BCL would be 'behind' whatever was offered by Windows.
  • the enum is likely to propagate across methods or APIs, such that it would be useful to pass the managed BCL type into an interop method.

@AArnott AArnott self-assigned this Sep 7, 2022
@AArnott AArnott removed good first issue Good for newcomers help wanted Extra attention is needed labels Sep 7, 2022
AArnott added a commit that referenced this issue Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants