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

Possibility to configure generation namespace name #683

Closed
Inurias opened this issue Sep 1, 2022 · 2 comments
Closed

Possibility to configure generation namespace name #683

Inurias opened this issue Sep 1, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@Inurias
Copy link

Inurias commented Sep 1, 2022

Problem

The readme of the project states:

Several aspects of the generated code can be customized, including:

  • ....
  • The namespace that declares all interop types
  • ...

But I can't find this setting for the NativeMethods.json or in GeneratorOptions.

I ran across a problem when using the generator when my code is inside a namespace that contains .Windows.
For example, writing Windows.Win32.Foundation.LRESULT results in VS attempting to find Win32.Foundation.LRESULT inside my own namespace Engine.Windowing.Windows. And emit an The type or namespace name 'Win32' does not exist in the namespace 'Engine.Windowing.Windows'. error.

Solution

It would be awesome if we could change the default namespace name. If I were to change it from Windows.Win32 to something like CsWin32 that solves the problem.

@Inurias Inurias added the enhancement New feature or request label Sep 1, 2022
AArnott added a commit that referenced this issue Sep 2, 2022
@AArnott
Copy link
Member

AArnott commented Sep 2, 2022

Thanks for bringing the doc to our attention. We used to allow customizing the namespace but removed it, leaving the doc behind. It turned out to create problems, particularly when multiple metadata inputs are used with CsWin32 together.

But you can solve your problem by adding global:: in front of the namespace. You can even create an alias for it to make it more convenient. For example at the top of your code file (or as a global using in just one file so it applies to your entire project):

using win32 = global::Windows.Win32;

Then everywhere you can use win32.Foundation.LRESULT and it will resolve correctly.
I hope that helps.

@AArnott AArnott closed this as not planned Won't fix, can't repro, duplicate, stale Sep 2, 2022
@Inurias
Copy link
Author

Inurias commented Sep 2, 2022

Thanks for bringing the doc to our attention. We used to allow customizing the namespace but removed it, leaving the doc behind. It turned out to create problems, particularly when multiple metadata inputs are used with CsWin32 together.

But you can solve your problem by adding global:: in front of the namespace. You can even create an alias for it to make it more convenient. For example at the top of your code file (or as a global using in just one file so it applies to your entire project):

using win32 = global::Windows.Win32;

Then everywhere you can use win32.Foundation.LRESULT and it will resolve correctly. I hope that helps.

Thank you, creating an alias is exactly what I did. If customizing the namespace created problems, then doing this instead is completely fine with me.

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

No branches or pull requests

2 participants