-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add polyfills for
OSPlatformAttribute
and its derivatives (#9)
- Loading branch information
Showing
7 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) | ||
#nullable enable | ||
// ReSharper disable RedundantUsingDirective | ||
// ReSharper disable CheckNamespace | ||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable PartialTypeWithSinglePart | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.Versioning; | ||
|
||
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.osplatformattribute | ||
[ExcludeFromCodeCoverage] | ||
internal abstract class OSPlatformAttribute(string platformName) : Attribute | ||
{ | ||
public string PlatformName { get; } = platformName; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) | ||
#nullable enable | ||
// ReSharper disable RedundantUsingDirective | ||
// ReSharper disable CheckNamespace | ||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable PartialTypeWithSinglePart | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.Versioning; | ||
|
||
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.supportedosplatformattribute | ||
[AttributeUsage( | ||
AttributeTargets.Assembly | ||
| AttributeTargets.Class | ||
| AttributeTargets.Constructor | ||
| AttributeTargets.Enum | ||
| AttributeTargets.Event | ||
| AttributeTargets.Field | ||
| AttributeTargets.Interface | ||
| AttributeTargets.Method | ||
| AttributeTargets.Module | ||
| AttributeTargets.Property | ||
| AttributeTargets.Struct, | ||
AllowMultiple = true, | ||
Inherited = false | ||
)] | ||
[ExcludeFromCodeCoverage] | ||
internal class SupportedOSPlatformAttribute(string platformName) | ||
: OSPlatformAttribute(platformName); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) | ||
#nullable enable | ||
// ReSharper disable RedundantUsingDirective | ||
// ReSharper disable CheckNamespace | ||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable PartialTypeWithSinglePart | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.Versioning; | ||
|
||
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.targetplatformattribute | ||
[AttributeUsage(AttributeTargets.Assembly)] | ||
[ExcludeFromCodeCoverage] | ||
internal class TargetPlatformAttribute(string platformName) : OSPlatformAttribute(platformName); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) | ||
#nullable enable | ||
// ReSharper disable RedundantUsingDirective | ||
// ReSharper disable CheckNamespace | ||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable PartialTypeWithSinglePart | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.Versioning; | ||
|
||
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.unsupportedosplatformattribute | ||
[AttributeUsage( | ||
AttributeTargets.Assembly | ||
| AttributeTargets.Class | ||
| AttributeTargets.Constructor | ||
| AttributeTargets.Enum | ||
| AttributeTargets.Event | ||
| AttributeTargets.Field | ||
| AttributeTargets.Interface | ||
| AttributeTargets.Method | ||
| AttributeTargets.Module | ||
| AttributeTargets.Property | ||
| AttributeTargets.Struct, | ||
AllowMultiple = true, | ||
Inherited = false | ||
)] | ||
[ExcludeFromCodeCoverage] | ||
internal class UnsupportedOSPlatformAttribute(string platformName, string? message = null) | ||
: OSPlatformAttribute(platformName) | ||
{ | ||
public string? Message { get; } = message; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#if (NETCOREAPP && !NET6_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) | ||
#nullable enable | ||
// ReSharper disable RedundantUsingDirective | ||
// ReSharper disable CheckNamespace | ||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable PartialTypeWithSinglePart | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.Versioning; | ||
|
||
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.supportedosplatformguardattribute | ||
[AttributeUsage( | ||
AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property, | ||
AllowMultiple = true, | ||
Inherited = false | ||
)] | ||
[ExcludeFromCodeCoverage] | ||
internal class SupportedOSPlatformGuardAttribute(string platformName) | ||
// OSPlatformAttribute's constructor is not accessible where that type is natively defined | ||
#if !(NETCOREAPP && NET5_0_OR_GREATER) | ||
: OSPlatformAttribute(platformName); | ||
#else | ||
: Attribute | ||
{ | ||
public string PlatformName { get; } = platformName; | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#if (NETCOREAPP && !NET6_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) | ||
#nullable enable | ||
// ReSharper disable RedundantUsingDirective | ||
// ReSharper disable CheckNamespace | ||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable PartialTypeWithSinglePart | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.Versioning; | ||
|
||
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.unsupportedosplatformguardattribute | ||
[AttributeUsage( | ||
AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property, | ||
AllowMultiple = true, | ||
Inherited = false | ||
)] | ||
[ExcludeFromCodeCoverage] | ||
internal class UnsupportedOSPlatformGuardAttribute(string platformName) | ||
// OSPlatformAttribute's constructor is not accessible where that type is natively defined | ||
#if !(NETCOREAPP && NET5_0_OR_GREATER) | ||
: OSPlatformAttribute(platformName); | ||
#else | ||
: Attribute | ||
{ | ||
public string PlatformName { get; } = platformName; | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#if (NETCOREAPP && !NET7_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) | ||
#nullable enable | ||
// ReSharper disable RedundantUsingDirective | ||
// ReSharper disable CheckNamespace | ||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable PartialTypeWithSinglePart | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.Versioning; | ||
|
||
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.obsoletedosplatformattribute | ||
[AttributeUsage( | ||
AttributeTargets.Assembly | ||
| AttributeTargets.Class | ||
| AttributeTargets.Constructor | ||
| AttributeTargets.Enum | ||
| AttributeTargets.Event | ||
| AttributeTargets.Field | ||
| AttributeTargets.Interface | ||
| AttributeTargets.Method | ||
| AttributeTargets.Module | ||
| AttributeTargets.Property | ||
| AttributeTargets.Struct, | ||
AllowMultiple = true, | ||
Inherited = false | ||
)] | ||
[ExcludeFromCodeCoverage] | ||
internal class ObsoletedOSPlatformAttribute(string platformName, string? message = null) | ||
// OSPlatformAttribute's constructor is not accessible where that type is natively defined | ||
#if !(NETCOREAPP && NET5_0_OR_GREATER) | ||
: OSPlatformAttribute(platformName) | ||
#else | ||
: Attribute | ||
#endif | ||
{ | ||
#if (NETCOREAPP && NET5_0_OR_GREATER) | ||
public string PlatformName { get; } = platformName; | ||
#endif | ||
|
||
public string? Message { get; } = message; | ||
|
||
public string? Url { get; init; } | ||
} | ||
#endif |