-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[API Proposal]: Expose options to only generate one direction for generated COM interfaces #86360
Comments
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsBackground and motivationCurrently, users must provide support in custom marshallers for API Proposalnamespace System.Runtime.InteropServices.Marshalling;
[AttributeUsage(AttributeTargets.Interface)]
public class GeneratedComInterfaceAttribute
{
+ public bool GenerateManagedObjectWrapper { get; } = true;
+ public bool GenerateComObjectWrapper { get; } = true;
} API Usage[GeneratedComInterface(GenerateManagedObjectWrapper = false)]
[Guid("e7ba7579-49ec-4d6a-905b-87fb4e476e36")]
interface IFoo
{
void Bar();
} Alternative DesignsContinue to require developers to handle marshallers going in both directions. RisksNo response
|
Love this 😄 Just out of curiosity, would there be any benefits other than binary size reduction from turning off either marshalling side, or would it be just for that? Not that it'd be a bad thing, just wondering if disabling either of those properties would also being any wins for perf or other things 🙂 |
No it’s really just to generate less code. There’s no other improvements this would provide. |
I'm fine with two |
I generally would prefer enums, my only thought is to avoid "ManagedToUnmanaged" and "UnmanagedToManaged" enum values. We usually mean that in the caller to callee, but with COM object, a runtime object passed to COM is passed from "Managed to Unmanaged", but then is called from Unmanaged to Managed, so that could be confusing IMO. |
I've updated the proposal to use an enum. Let me know what you think of the naming/shape! |
I like it! Nit: I feel the "Generated" prefix on the enum isn't strictly necessary, and removing it might make the type potentially more general, which might or might not be potentially useful in other scenarios in the future? Other than that LGTM 😄 |
namespace System.Runtime.InteropServices.Marshalling; [Flags]
public enum ComInterfaceOptions
{
None = 0,
ManagedObjectWrapper = 0x1,
ComObjectWrapper = 0x2,
}
[AttributeUsage(AttributeTargets.Interface)]
public sealed partial class GeneratedComInterfaceAttribute
{
public ComInterfaceOptions Options { get; set; } = ComInterfaceOptions.ManagedObjectWrapper | ComInterfaceOptions.ComObjectWrapper;
} |
Just watched the API review — shouldn't the setter be |
It looks like for attributes, we usually just do |
Background and motivation
Currently, users must provide support in custom marshallers for
[GeneratedComInterface]
APIs for both managed-to-unmanaged and unmanaged-to-managed. Many COM interfaces are meant to be consumed from managed code either by calling into a COM component implemented elsewhere or implementing a COM component that will be called from non-.NET code. This proposal adds members on the[GeneratedComInterface]
attribute to support turning off either the managed->unmanaged or the unmanaged->managed direction of code-gen.API Proposal
API Usage
Alternative Designs
bool
properties instead of an enum.Risks
No response
The text was updated successfully, but these errors were encountered: