Skip to content

[API Proposal]: Add System.Runtime.CompilerServices.RefSafetyRulesAttribute #76032

Description

@cston

Background and motivation

The C# compiler emits a [module: RefSafetyRules(11)] attribute to modules compiled with -langversion:11 or above, or compiled with .NET 7 or above, to indicate that the module was compiled with C#11 ref safety rules.

The RefSafetyRulesAttribute type definition should be added to the BCL to avoid having the compiler emit the attribute definition to each module.

See RefSafetyRulesAttribute.

API Proposal

namespace System.Runtime.CompilerServices
{
    [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
    public sealed class RefSafetyRulesAttribute : Attribute
    {
        public RefSafetyRulesAttribute(int version) { Version = version; }
        public int Version;
    }
}

API Usage

The RefSafetyRulesAttribute type is for compiler use only - it is not permitted in source.

Alternative Designs

No response

Risks

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions