Skip to content

Commit bbfd2f8

Browse files
committed
Add OverloadResolutionPriorityAttribute
Closes #102173.
1 parent 0129837 commit bbfd2f8

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-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
@@ -877,6 +877,7 @@
877877
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\PoolingAsyncValueTaskMethodBuilder.cs" />
878878
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\PoolingAsyncValueTaskMethodBuilderT.cs" />
879879
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\PreserveBaseOverridesAttribute.cs" />
880+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\OverloadResolutionPriorityAttribute.cs" />
880881
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RefSafetyRulesAttribute.cs" />
881882
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RequiredMemberAttribute.cs" />
882883
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RequiresLocationAttribute.cs" />
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>
7+
/// Specifies the priority of a member in overload resolution. When unspecified, the default priority is 0.
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
10+
public sealed class OverloadResolutionPriorityAttribute(int priority)
11+
{
12+
/// <summary>
13+
/// The priority of the member.
14+
/// </summary>
15+
public int Priority { get; } = priority;
16+
}
17+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13091,6 +13091,13 @@ public sealed partial class NullablePublicOnlyAttribute : System.Attribute
1309113091
public readonly bool IncludesInternals;
1309213092
public NullablePublicOnlyAttribute(bool value) { }
1309313093
}
13094+
[System.AttributeUsageAttribute(System.AttributeTargets.Method | System.AttributeTargets.Constructor | System.AttributeTargets.Property, Inherited=false)]
13095+
public sealed partial class RequiresDynamicCodeAttribute : System.Attribute
13096+
{
13097+
public RequiresDynamicCodeAttribute(string message) { }
13098+
public string Message { get { throw null; } }
13099+
public string? Url { get { throw null; } set { } }
13100+
}
1309413101
[System.AttributeUsageAttribute(System.AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)]
1309513102
public sealed partial class ParamCollectionAttribute : System.Attribute
1309613103
{

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,5 +399,12 @@ public static void RequiresLocationAttributeTests()
399399
{
400400
new RequiresLocationAttribute();
401401
}
402+
403+
[Fact]
404+
public static void OverloadResolutionPriorityAttributeTests()
405+
{
406+
var attr = new OverloadResolutionPriorityAttribute(42);
407+
Assert.Equal(42, attr.Priority);
408+
}
402409
}
403410
}

0 commit comments

Comments
 (0)