Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1816 from jnyrup/StringSyntaxAttribute
Annotated [Not]MatchRegex with [StringSyntax("Regex")]
- Loading branch information
Showing
3 changed files
with
58 additions
and
2 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
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,52 @@ | ||
// copied from https://raw.githubusercontent.com/dotnet/runtime/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/StringSyntaxAttribute.cs | ||
#if !NET7_0_OR_GREATER | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
namespace System.Diagnostics.CodeAnalysis | ||
{ | ||
/// <summary>Specifies the syntax used in a string.</summary> | ||
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)] | ||
#if SYSTEM_PRIVATE_CORELIB | ||
public | ||
#else | ||
internal | ||
#endif | ||
sealed class StringSyntaxAttribute : Attribute | ||
{ | ||
/// <summary>Initializes the <see cref="StringSyntaxAttribute"/> with the identifier of the syntax used.</summary> | ||
/// <param name="syntax">The syntax identifier.</param> | ||
public StringSyntaxAttribute(string syntax) | ||
{ | ||
Syntax = syntax; | ||
Arguments = Array.Empty<object?>(); | ||
} | ||
|
||
/// <summary>Initializes the <see cref="StringSyntaxAttribute"/> with the identifier of the syntax used.</summary> | ||
/// <param name="syntax">The syntax identifier.</param> | ||
/// <param name="arguments">Optional arguments associated with the specific syntax employed.</param> | ||
public StringSyntaxAttribute(string syntax, params object?[] arguments) | ||
{ | ||
Syntax = syntax; | ||
Arguments = arguments; | ||
} | ||
|
||
/// <summary>Gets the identifier of the syntax used.</summary> | ||
public string Syntax { get; } | ||
|
||
/// <summary>Optional arguments associated with the specific syntax employed.</summary> | ||
public object?[] Arguments { get; } | ||
|
||
/// <summary>The syntax identifier for strings containing date and time format specifiers.</summary> | ||
public const string DateTimeFormat = nameof(DateTimeFormat); | ||
|
||
/// <summary>The syntax identifier for strings containing JavaScript Object Notation (JSON).</summary> | ||
public const string Json = nameof(Json); | ||
|
||
/// <summary>The syntax identifier for strings containing regular expressions.</summary> | ||
public const string Regex = nameof(Regex); | ||
} | ||
} | ||
#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