Improve optional out interface arguments (e.g. IWbemServices.GetObject) and other minor tweaks #1544
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One reason that parameters were still showing up as pointers in the friendly overloads was because of
[optional, out]parameters. For example, IWbemServices.GetObject has two out parameters which are optional and are also interfaces. As we've seen with other optional out/ref parameters, we have to leave these as pointers in the ABI so that they can be passed as "null". #1511 improved things for optional out/ref types that are trivially marshallable, but a case that is particularly unpleasant to deal with as pointers is COM interfaces.This change improves things so that on the friendly overload that includes optional parameters, the out/ref interfaces are upgraded to managed interfaces and the implementation handles the COM marshalling both for source-generated COM and built-in COM. The helpers also handle
Unsafe.NullRef<T>being passed in for the optional parameters in case you want to omit some, same as you can do with the upgraded optional value type params.I added a test case that demonstrates calling
IWbemServices.GetObjectwhich is much simpler than the unmanaged alternative.I also fixed a couple other minor things:
Here's what the generated code looks like (for a function that has just one optional out parameter of this kind) if you don't want to build locally to take a look:
Fixes #1066, Fixes #1528, Fixes #1216, Fixes #1185, Fixes #1066, Fixes #137