Skip to content

[API Proposal]: Optional export of UnmanagedCallersOnlyAttribute #114733

@HolographicHat

Description

@HolographicHat

Background and motivation

Some funcs are only used for native interop with static libraries and we don't want them exported, so we need a new field to UnmanagedCallersOnlyAttribute to control whether the method is exported.

API Proposal

    [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited = false)]
    public sealed class UnmanagedCallersOnlyAttribute : System.Attribute
    {
         public UnmanagedCallersOnlyAttribute() { }
         public System.Type[]? CallConvs;
         public string? EntryPoint;
+        public bool Export = true;
     }

API Usage

[UnmanagedCallersOnly(EntryPoint = "InternalSum", Export = false)]
public static int InternalSum(int a, int b) => a + b;
extern "C" int InternalSum(int a, int b);

extern "C" __declspec(dllexport) capi_get_number() {
    return InternalSum(114, 514);
}

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions