Skip to content

Commit 6a2efbb

Browse files
authored
Merge pull request #5 from Sergio0694/dev/preview-features
Add [RequiresPreviewFeatures] polyfill
2 parents 72a0290 + 0bd3da2 commit 6a2efbb

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- `[InterpolatedStringHandler]`
3333
- `[InterpolatedStringHandlerArgument]`
3434
- `[CallerArgumentExpression]` (see [docs](https://learn.microsoft.com/dotnet/csharp/language-reference/proposals/csharp-10.0/caller-argument-expression))
35+
- `[RequiresPreviewFeatures]` (needed for [preview features](https://github.com/dotnet/designs/blob/main/accepted/2021/preview-features/preview-features.md))
3536

3637
To leverage them, make sure to bump your C# language version. You can do this by setting the `<LangVersion>` MSBuild property in your project. For instance, by adding `<LangVersion>11.0</LangVersion>` (or your desired C# version) to the first `<PropertyGroup>` of your .csproj file. For more info on this, [see here](https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb), but remember that you don't need to manually copy polyfills anymore: simply adding a reference to **PolySharp** will do this for you automatically.
3738

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// <auto-generated/>
2+
#pragma warning disable
3+
#nullable enable annotations
4+
5+
// Licensed to the .NET Foundation under one or more agreements.
6+
// The .NET Foundation licenses this file to you under the MIT license.
7+
8+
namespace System.Runtime.Versioning
9+
{
10+
[AttributeUsage(AttributeTargets.Assembly |
11+
AttributeTargets.Module |
12+
AttributeTargets.Class |
13+
AttributeTargets.Interface |
14+
AttributeTargets.Delegate |
15+
AttributeTargets.Struct |
16+
AttributeTargets.Enum |
17+
AttributeTargets.Constructor |
18+
AttributeTargets.Method |
19+
AttributeTargets.Property |
20+
AttributeTargets.Field |
21+
AttributeTargets.Event, Inherited = false)]
22+
internal sealed class RequiresPreviewFeaturesAttribute : Attribute
23+
{
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="RequiresPreviewFeaturesAttribute"/> class.
26+
/// </summary>
27+
public RequiresPreviewFeaturesAttribute() { }
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="RequiresPreviewFeaturesAttribute"/> class with the specified message.
31+
/// </summary>
32+
/// <param name="message">An optional message associated with this attribute instance.</param>
33+
public RequiresPreviewFeaturesAttribute(string? message)
34+
{
35+
Message = message;
36+
}
37+
38+
/// <summary>
39+
/// Returns the optional message associated with this attribute instance.
40+
/// </summary>
41+
public string? Message { get; }
42+
43+
/// <summary>
44+
/// Returns the optional URL associated with this attribute instance.
45+
/// </summary>
46+
public string? Url { get; set; }
47+
}
48+
}

tests/PolySharp.Tests/LanguageFeatures.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics.CodeAnalysis;
33
using System.Runtime.CompilerServices;
4+
using System.Runtime.Versioning;
45

56
namespace PolySharp.Tests;
67

@@ -81,6 +82,11 @@ public bool TakeValue([NotNullWhen(true)] out string? value)
8182

8283
return true;
8384
}
85+
86+
[RequiresPreviewFeatures]
87+
public void PreviewApi()
88+
{
89+
}
8490
}
8591

8692
internal class TestClassWithRequiredMembers

0 commit comments

Comments
 (0)