diff --git a/README.md b/README.md index d8cefac..e579273 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ - `[InterpolatedStringHandler]` - `[InterpolatedStringHandlerArgument]` - `[CallerArgumentExpression]` (see [docs](https://learn.microsoft.com/dotnet/csharp/language-reference/proposals/csharp-10.0/caller-argument-expression)) +- `[RequiresPreviewFeatures]` (needed for [preview features](https://github.com/dotnet/designs/blob/main/accepted/2021/preview-features/preview-features.md)) To leverage them, make sure to bump your C# language version. You can do this by setting the `` MSBuild property in your project. For instance, by adding `11.0` (or your desired C# version) to the first `` 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. diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs new file mode 100644 index 0000000..393a334 --- /dev/null +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable +#nullable enable annotations + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Runtime.Versioning +{ + [AttributeUsage(AttributeTargets.Assembly | + AttributeTargets.Module | + AttributeTargets.Class | + AttributeTargets.Interface | + AttributeTargets.Delegate | + AttributeTargets.Struct | + AttributeTargets.Enum | + AttributeTargets.Constructor | + AttributeTargets.Method | + AttributeTargets.Property | + AttributeTargets.Field | + AttributeTargets.Event, Inherited = false)] + internal sealed class RequiresPreviewFeaturesAttribute : Attribute + { + /// + /// Initializes a new instance of the class. + /// + public RequiresPreviewFeaturesAttribute() { } + + /// + /// Initializes a new instance of the class with the specified message. + /// + /// An optional message associated with this attribute instance. + public RequiresPreviewFeaturesAttribute(string? message) + { + Message = message; + } + + /// + /// Returns the optional message associated with this attribute instance. + /// + public string? Message { get; } + + /// + /// Returns the optional URL associated with this attribute instance. + /// + public string? Url { get; set; } + } +} \ No newline at end of file diff --git a/tests/PolySharp.Tests/LanguageFeatures.cs b/tests/PolySharp.Tests/LanguageFeatures.cs index ff40c4a..eb51a2d 100644 --- a/tests/PolySharp.Tests/LanguageFeatures.cs +++ b/tests/PolySharp.Tests/LanguageFeatures.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; +using System.Runtime.Versioning; namespace PolySharp.Tests; @@ -81,6 +82,11 @@ public bool TakeValue([NotNullWhen(true)] out string? value) return true; } + + [RequiresPreviewFeatures] + public void PreviewApi() + { + } } internal class TestClassWithRequiredMembers