microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
2.1k stars 90 forks source link

Optionally put imported method in separate classes (by module) #826

Closed TymurGubayev closed 1 year ago

TymurGubayev commented 1 year ago

Is your feature request related to a problem? Please describe. I need to import lots of APIs from different modules (most notable are kernel32 and user32). I'd like a way to keep them in different namespaces, i.e.

kernel32.Sleep(100);
user32.MessageBeep(0);

Right now all imported functions are thrown together into a single class (Windows.Win32.PInvoke by default).

Describe the solution you'd like I'd like an option to have imported method in separate classes (corresponding to modules they were imported from), especially if the import is done with the "match all"-pattern (f.e. kernel32.*).

Describe alternatives you've considered A solution is to generate each class once and make them permanent part of the solution, not auto-generated.

Additional context

AArnott commented 1 year ago

Thank you for your feedback. We actually originally had this feature, but removed it in #444 because it added complexity to CsWin32 which is already quite complex, and it didn't match the native development experience where all methods are in the global namespace anyway.