Skip to content

Commit 0e4433a

Browse files
authored
Add polyfill for OverloadResolutionPriorityAttribute (#19)
1 parent d063b63 commit 0e4433a

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Runtime.CompilerServices;
2+
using FluentAssertions;
3+
using Xunit;
4+
5+
namespace PolyShim.Tests.Net90;
6+
7+
public class OverloadResolutionPriorityAttributeTests
8+
{
9+
[OverloadResolutionPriority(1)]
10+
private int Foo(int value = 0) => value;
11+
12+
private int Foo() => 42;
13+
14+
[Fact]
15+
public void Initialization_Test()
16+
{
17+
// Act & assert
18+
Foo().Should().Be(0);
19+
}
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// The following comment is required to instruct analyzers to skip this file
2+
// <auto-generated/>
3+
4+
#if (NETCOREAPP && !NET9_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD)
5+
#nullable enable
6+
#pragma warning disable CS9216
7+
// ReSharper disable RedundantUsingDirective
8+
// ReSharper disable CheckNamespace
9+
// ReSharper disable InconsistentNaming
10+
// ReSharper disable PartialTypeWithSinglePart
11+
12+
using System.Diagnostics.CodeAnalysis;
13+
14+
namespace System.Runtime.CompilerServices;
15+
16+
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.overloadresolutionpriorityattribute
17+
[ExcludeFromCodeCoverage]
18+
[AttributeUsage(
19+
AttributeTargets.Constructor
20+
| AttributeTargets.Method
21+
| AttributeTargets.Property,
22+
Inherited = false
23+
)]
24+
internal class OverloadResolutionPriorityAttribute(int priority) : Attribute
25+
{
26+
public int Priority { get; } = priority;
27+
}
28+
#endif

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ To learn more about the war and how you can help, [click here](https://tyrrrz.me
4545
- Required properties
4646
- Named tuples
4747
- Module initializers
48+
- Overload priority
4849
- & more...
4950
- Provides type polyfills for:
5051
- `ValueTuple<...>`

0 commit comments

Comments
 (0)