Skip to content

Commit 06e8c92

Browse files
authored
Add public RefSafetyRulesAttribute (#80379)
1 parent 78f5a98 commit 06e8c92

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@
806806
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\PoolingAsyncValueTaskMethodBuilder.cs" />
807807
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\PoolingAsyncValueTaskMethodBuilderT.cs" />
808808
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\PreserveBaseOverridesAttribute.cs" />
809+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RefSafetyRulesAttribute.cs" />
809810
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RequiredMemberAttribute.cs" />
810811
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeCompatibilityAttribute.cs" />
811812
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeFeature.cs" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Runtime.CompilerServices
5+
{
6+
/// <summary>Indicates the language version of the ref safety rules used when the module was compiled.</summary>
7+
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
8+
public sealed class RefSafetyRulesAttribute : Attribute
9+
{
10+
/// <summary>Initializes a new instance of the <see cref="RefSafetyRulesAttribute"/> class.</summary>
11+
/// <param name="version">The language version of the ref safety rules used when the module was compiled.</param>
12+
public RefSafetyRulesAttribute(int version) => Version = version;
13+
14+
/// <summary>Gets the language version of the ref safety rules used when the module was compiled.</summary>
15+
public int Version { get; }
16+
}
17+
}

src/libraries/System.Runtime/ref/System.Runtime.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12549,6 +12549,12 @@ public sealed partial class PreserveBaseOverridesAttribute : System.Attribute
1254912549
{
1255012550
public PreserveBaseOverridesAttribute() { }
1255112551
}
12552+
[System.AttributeUsage(System.AttributeTargets.Module, AllowMultiple=false, Inherited=false)]
12553+
public sealed partial class RefSafetyRulesAttribute : System.Attribute
12554+
{
12555+
public RefSafetyRulesAttribute(int version) { }
12556+
public int Version { get { throw null; } }
12557+
}
1255212558
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
1255312559
public sealed class RequiredMemberAttribute : System.Attribute
1255412560
{

src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/AttributesTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ public static void MethodImplAttributeTests()
192192
Assert.Equal(MethodImplOptions.Unmanaged, attr3.Value);
193193
}
194194

195+
[Theory]
196+
[InlineData(-1)]
197+
[InlineData(42)]
198+
public static void RefSafetyRulesAttributeTests(int version)
199+
{
200+
var attr = new RefSafetyRulesAttribute(version);
201+
Assert.Equal(version, attr.Version);
202+
}
203+
195204
[Fact]
196205
public static void ReferenceAssemblyAttributeTests()
197206
{

0 commit comments

Comments
 (0)