Skip to content

Commit 09dd34e

Browse files
authored
Add OverloadResolutionPriorityAttribute (#102176)
* Add OverloadResolutionPriorityAttribute Closes #102173. * Base types * Switch from primary ctor to regular ctor, add docs.
1 parent c12c3b7 commit 09dd34e

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

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" />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 : Attribute
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="OverloadResolutionPriorityAttribute"/> class.
14+
/// </summary>
15+
/// <param name="priority">The priority of the attributed member. Higher numbers are prioritized, lower numbers are deprioritized. 0 is the default if no attribute is present.</param>
16+
public OverloadResolutionPriorityAttribute(int priority)
17+
{
18+
Priority = priority;
19+
}
20+
21+
/// <summary>
22+
/// The priority of the member.
23+
/// </summary>
24+
public int Priority { get; }
25+
}
26+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13091,6 +13091,12 @@ 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, AllowMultiple=false, Inherited=false)]
13095+
public sealed partial class OverloadResolutionPriorityAttribute : System.Attribute
13096+
{
13097+
public OverloadResolutionPriorityAttribute(int priority) { }
13098+
public int Priority { get { throw null; } }
13099+
}
1309413100
[System.AttributeUsageAttribute(System.AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)]
1309513101
public sealed partial class ParamCollectionAttribute : System.Attribute
1309613102
{

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)