-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom string interpolation handlers.
- Loading branch information
Showing
3 changed files
with
97 additions
and
1 deletion.
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
57 changes: 57 additions & 0 deletions
57
...t.Polyfills/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs
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,57 @@ | ||
#if NET6_0_OR_GREATER | ||
|
||
#if POLYKIT_PUBLIC | ||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute))] | ||
#endif | ||
|
||
#else | ||
|
||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.CompilerServices; | ||
|
||
// https://github.com/dotnet/runtime/blob/v6.0.8/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs | ||
|
||
/// <summary> | ||
/// Indicates which arguments to a method involving an interpolated string handler should be passed to that handler. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] | ||
[ExcludeFromCodeCoverage, DebuggerNonUserCode] | ||
#if POLYKIT_PUBLIC | ||
public | ||
#else | ||
internal | ||
#endif | ||
sealed class InterpolatedStringHandlerArgumentAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class. | ||
/// </summary> | ||
/// <param name="argument">The name of the argument that should be passed to the handler.</param> | ||
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks> | ||
#pragma warning disable CA1019 // Define accessors for attribute arguments - Preserving original code. | ||
public InterpolatedStringHandlerArgumentAttribute(string argument) | ||
#pragma warning restore CA1019 // Define accessors for attribute arguments | ||
{ | ||
Arguments = new string[] { argument }; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class. | ||
/// </summary> | ||
/// <param name="arguments">The names of the arguments that should be passed to the handler.</param> | ||
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks> | ||
public InterpolatedStringHandlerArgumentAttribute(params string[] arguments) | ||
{ | ||
Arguments = arguments; | ||
} | ||
|
||
/// <summary>Gets the names of the arguments that should be passed to the handler.</summary> | ||
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks> | ||
public string[] Arguments { get; } | ||
} | ||
|
||
#endif |
38 changes: 38 additions & 0 deletions
38
src/PolyKit.Polyfills/System/Runtime/CompilerServices/InterpolatedStringHandlerAttribute.cs
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,38 @@ | ||
#if NET6_0_OR_GREATER | ||
|
||
#if POLYKIT_PUBLIC | ||
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute))] | ||
#endif | ||
|
||
#else | ||
|
||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.Runtime.CompilerServices; | ||
|
||
// https://github.com/dotnet/runtime/blob/v6.0.8/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/InterpolatedStringHandlerAttribute.cs | ||
|
||
/// <summary> | ||
/// Indicates the attributed type is to be used as an interpolated string handler. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] | ||
[ExcludeFromCodeCoverage, DebuggerNonUserCode] | ||
#if POLYKIT_PUBLIC | ||
public | ||
#else | ||
internal | ||
#endif | ||
sealed class InterpolatedStringHandlerAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerAttribute"/> class. | ||
/// </summary> | ||
public InterpolatedStringHandlerAttribute() | ||
{ | ||
} | ||
} | ||
|
||
#endif |