-
Couldn't load subscription status.
- Fork 113
Description
Is your feature request related to a problem? Please describe.
When composing multiple assemblies that use CsWin32 you need to have multiple definitions of the main static class. In WinForms this ends up being PInvokeCore and PInvoke. This makes discovery difficult.
Describe the solution you'd like
Allow specifying an extension receiver class name that will result in the static class generating a specified extension scope.
In the NativeMethods.json:
{
"$schema": "https://aka.ms/CsWin32.schema.json",
"className": "WinFormsPInvokes",
"extensionReciever": "PInvoke"
}Generates (effectively):
namespace Windows.Win32;
internal partial static class WinFormsPInvokes
{
extension (PInvoke)
{
// All defines generated here
}
}This feature requires C# 14 (with .NET 10) to compile but works on both .NET Framework and .NET (core). You can still reference the members directly via the static class name so consuming libraries can still use this without using C# 14. I don't think it is necessary to add any deduplication logic as part of this initial feature request.
Documentation:
https://learn.microsoft.com/dotnet/csharp/whats-new/csharp-14#extension-members
https://learn.microsoft.com/dotnet/csharp/language-reference/proposals/csharp-14.0/extensions
Describe alternatives you've considered
There aren't any other good options that I'm aware of.
Additional context
Add any other context or screenshots about the feature request here.