Repository navigation
Should I not expose private Win32 types? #1796
|
When I use types like HWND or BITMAPINFO, they are private by default. Should I not expose these types? Sometimes I can force them to be public, with this I think... { Mostly this has worked, but sometimes it doesn't. Here's a capture of HWND showing that it's private, while underneath you can see that public = true.
So it seems unstable or something depending on unknown factors. It makes me wonder if I should expose Win32 types at all. If they are private by default, maybe that's for a good reason. And everything should be in a wrapper. What's the right way here? |
Replies: 2 comments 1 reply
|
Generally you should not expose CsWin32 types as public because these kinds of win32 APIs are implementation details of a component, that's why it's private by default. But within some components (E.g. in WinForms) there is more sharing happening and so Jeremy Kuhne (@JeremyKuhne) implemented #1477. |
|
Jevan Saks (@jevansaks) answered the "should I", and the source backs up why that's the only sane default:
private SyntaxKind Visibility => this.options.Public ? SyntaxKind.PublicKeyword : SyntaxKind.InternalKeyword;Every emitter — On the other half — "seems unstable depending on unknown factors" — there are two mechanisms that produce what you're seeing, and one line tells you which: 1. Your .FirstOrDefault(af => Path.GetFileName(af.Path).EndsWith(NativeMethodsJsonAdditionalFileName, StringComparison.OrdinalIgnoreCase));
The check, no rebuilding required: open any generated file and look at the this.fileHeader = this.options.Public ? FileHeader : FileHeaderWithClsArrayAttributeSuppression;and the second one is the first plus
2. Some members are unconditionally public by design. In Worth ruling out #1 first, since it's the one that would explain the same JSON behaving differently across projects. |

Generally you should not expose CsWin32 types as public because these kinds of win32 APIs are implementation details of a component, that's why it's private by default. But within some components (E.g. in WinForms) there is more sharing happening and so Jeremy Kuhne (@JeremyKuhne) implemented #1477.