Skip to content

Commit

Permalink
Merge pull request #5 from Sergio0694/dev/preview-features
Browse files Browse the repository at this point in the history
Add [RequiresPreviewFeatures] polyfill
  • Loading branch information
Sergio0694 authored Oct 23, 2022
2 parents 72a0290 + 0bd3da2 commit 6a2efbb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<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.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// <auto-generated/>
#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
{
/// <summary>
/// Initializes a new instance of the <see cref="RequiresPreviewFeaturesAttribute"/> class.
/// </summary>
public RequiresPreviewFeaturesAttribute() { }

/// <summary>
/// Initializes a new instance of the <see cref="RequiresPreviewFeaturesAttribute"/> class with the specified message.
/// </summary>
/// <param name="message">An optional message associated with this attribute instance.</param>
public RequiresPreviewFeaturesAttribute(string? message)
{
Message = message;
}

/// <summary>
/// Returns the optional message associated with this attribute instance.
/// </summary>
public string? Message { get; }

/// <summary>
/// Returns the optional URL associated with this attribute instance.
/// </summary>
public string? Url { get; set; }
}
}
6 changes: 6 additions & 0 deletions tests/PolySharp.Tests/LanguageFeatures.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

namespace PolySharp.Tests;

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

return true;
}

[RequiresPreviewFeatures]
public void PreviewApi()
{
}
}

internal class TestClassWithRequiredMembers
Expand Down

0 comments on commit 6a2efbb

Please sign in to comment.