Skip to content

Commit

Permalink
Add polyfills for RequiresDynamicCodeAttribute, `RequiresUnreferenc…
Browse files Browse the repository at this point in the history
…edCodeAttribute`, and `UnconditionalSuppressMessageAttribute` (#7)
  • Loading branch information
Tyrrrz authored May 22, 2024
1 parent 5133444 commit 60900cd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PolyShim/Net50/DynamicallyAccessedMemberTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ internal enum DynamicallyAccessedMemberTypes
NonPublicProperties = 1024,
PublicEvents = 2048,
NonPublicEvents = 4096,
Interfaces = 8192,
Interfaces = 8192
}
#endif
22 changes: 22 additions & 0 deletions PolyShim/Net50/RequiresUnreferencedCodeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD)
#nullable enable
// ReSharper disable RedundantUsingDirective
// ReSharper disable CheckNamespace
// ReSharper disable InconsistentNaming
// ReSharper disable PartialTypeWithSinglePart

namespace System.Diagnostics.CodeAnalysis;

// https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.requiresunreferencedcodeattribute
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Method,
Inherited = false
)]
[ExcludeFromCodeCoverage]
internal class RequiresUnreferencedCodeAttribute(string message) : Attribute
{
public string Message { get; } = message;

public string? Url { get; init; }
}
#endif
27 changes: 27 additions & 0 deletions PolyShim/Net50/UnconditionalSuppressMessageAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD)
#nullable enable
// ReSharper disable RedundantUsingDirective
// ReSharper disable CheckNamespace
// ReSharper disable InconsistentNaming
// ReSharper disable PartialTypeWithSinglePart

namespace System.Diagnostics.CodeAnalysis;

// https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.unconditionalsuppressmessageattribute
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
internal class UnconditionalSuppressMessageAttribute(string category, string checkId) : Attribute
{
public string Category { get; } = category;

public string CheckId { get; } = checkId;

public string? MessageId { get; init; }

public string? Justification { get; init; }

public string? Scope { get; init; }

public string? Target { get; init; }
}
#endif
22 changes: 22 additions & 0 deletions PolyShim/Net70/RequiresDynamicCodeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#if (NETCOREAPP && !NET7_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD)
#nullable enable
// ReSharper disable RedundantUsingDirective
// ReSharper disable CheckNamespace
// ReSharper disable InconsistentNaming
// ReSharper disable PartialTypeWithSinglePart

namespace System.Diagnostics.CodeAnalysis;

// https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.requiresdynamiccodeattribute
[AttributeUsage(
AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Method,
Inherited = false
)]
[ExcludeFromCodeCoverage]
internal class RequiresDynamicCodeAttribute(string message) : Attribute
{
public string Message { get; } = message;

public string? Url { get; init; }
}
#endif

0 comments on commit 60900cd

Please sign in to comment.