Skip to content

Commit

Permalink
Added "polyfills" to allow internal usage of some C#11 compiler featu…
Browse files Browse the repository at this point in the history
…res, including the `required` and `init` keywords. (#772)

Co-authored-by: Chris Pulman <chris.pulman@yahoo.com>
  • Loading branch information
JakenVeina and ChrisPulman committed Dec 3, 2023
1 parent ab11599 commit 70e02b5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/DynamicData/Polyfills/CompilerFeatureRequiredAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2011-2023 Roland Pheasant. All rights reserved.
// Roland Pheasant licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

namespace System.Runtime.CompilerServices;

// Allows use of the C#11 `required` keyword, internally within this library, when targeting frameworks older than .NET 7.
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute
: Attribute
{
public CompilerFeatureRequiredAttribute(string featureName)
=> FeatureName = featureName;

public string FeatureName { get; }

public bool IsOptional { get; init; }

public const string RefStructs
= nameof(RefStructs);

public const string RequiredMembers
= nameof(RequiredMembers);
}
10 changes: 10 additions & 0 deletions src/DynamicData/Polyfills/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2011-2023 Roland Pheasant. All rights reserved.
// Roland Pheasant licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

namespace System.Runtime.CompilerServices;

// Allows use of the C#11 `init` keyword, internally within this library, when targeting frameworks older than .NET 5.
internal sealed class IsExternalInit

Check warning on line 8 in src/DynamicData/Polyfills/IsExternalInit.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Remove this empty class, write its code or make it an "interface". (https://rules.sonarsource.com/csharp/RSPEC-2094)

Check warning on line 8 in src/DynamicData/Polyfills/IsExternalInit.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Remove this empty class, write its code or make it an "interface". (https://rules.sonarsource.com/csharp/RSPEC-2094)
{
}
15 changes: 15 additions & 0 deletions src/DynamicData/Polyfills/RequiredMemberAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2011-2023 Roland Pheasant. All rights reserved.
// Roland Pheasant licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.ComponentModel;

namespace System.Runtime.CompilerServices;

// Allows use of the C#11 `required` keyword, internally within this library, when targeting frameworks older than .NET 7.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[EditorBrowsable(EditorBrowsableState.Never)]
internal sealed class RequiredMemberAttribute
: Attribute
{
}

0 comments on commit 70e02b5

Please sign in to comment.