diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.cs b/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.cs
index 8cac9db32a9767..c315783ab58c0f 100644
--- a/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.cs
+++ b/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.cs
@@ -41,6 +41,7 @@ public partial class ConsoleFormatterOptions
{
public ConsoleFormatterOptions() { }
public bool IncludeScopes { get { throw null; } set { } }
+ [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.DateTimeFormat)]
public string TimestampFormat { get { throw null; } set { } }
public bool UseUtcTimestamp { get { throw null; } set { } }
}
diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.csproj b/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.csproj
index ba0bf1821d39dd..71aeb235fd3b01 100644
--- a/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.csproj
+++ b/src/libraries/Microsoft.Extensions.Logging.Console/ref/Microsoft.Extensions.Logging.Console.csproj
@@ -14,6 +14,10 @@
+
+
+
+
diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleFormatterOptions.cs b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleFormatterOptions.cs
index 0fcdd2f038ef98..e4a9800ad6e3e1 100644
--- a/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleFormatterOptions.cs
+++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleFormatterOptions.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Microsoft.Extensions.Logging.Console
@@ -21,6 +22,7 @@ public ConsoleFormatterOptions() { }
///
/// Gets or sets format string used to format timestamp in logging messages. Defaults to null.
///
+ [StringSyntax(StringSyntaxAttribute.DateTimeFormat)]
public string TimestampFormat { get; set; }
///
diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj b/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj
index 9256474085a479..e3bc7f50b436b2 100644
--- a/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj
+++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/Microsoft.Extensions.Logging.Console.csproj
@@ -1,4 +1,4 @@
-
+
$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)
@@ -38,6 +38,10 @@
+
+
+
+
@@ -63,4 +67,4 @@
-
\ No newline at end of file
+
diff --git a/src/libraries/System.ComponentModel.Annotations/ref/System.ComponentModel.Annotations.cs b/src/libraries/System.ComponentModel.Annotations/ref/System.ComponentModel.Annotations.cs
index c78333ddf64333..cc7dfb6120ef18 100644
--- a/src/libraries/System.ComponentModel.Annotations/ref/System.ComponentModel.Annotations.cs
+++ b/src/libraries/System.ComponentModel.Annotations/ref/System.ComponentModel.Annotations.cs
@@ -235,7 +235,7 @@ public RangeAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMember
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false)]
public partial class RegularExpressionAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
{
- public RegularExpressionAttribute(string pattern) { }
+ public RegularExpressionAttribute([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex)] string pattern) { }
public int MatchTimeoutInMilliseconds { get { throw null; } set { } }
public string Pattern { get { throw null; } }
public override string FormatErrorMessage(string name) { throw null; }
diff --git a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/RegularExpressionAttribute.cs b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/RegularExpressionAttribute.cs
index e7f4eb1db432e4..cf2ec8a7697c20 100644
--- a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/RegularExpressionAttribute.cs
+++ b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/RegularExpressionAttribute.cs
@@ -1,6 +1,7 @@
// 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.CodeAnalysis;
using System.Globalization;
using System.Text.RegularExpressions;
@@ -17,7 +18,7 @@ public class RegularExpressionAttribute : ValidationAttribute
/// Constructor that accepts the regular expression pattern
///
/// The regular expression to use. It cannot be null.
- public RegularExpressionAttribute(string pattern)
+ public RegularExpressionAttribute([StringSyntax(StringSyntaxAttribute.Regex)] string pattern)
: base(() => SR.RegexAttribute_ValidationError)
{
Pattern = pattern;
diff --git a/src/libraries/System.Net.WebProxy/ref/System.Net.WebProxy.cs b/src/libraries/System.Net.WebProxy/ref/System.Net.WebProxy.cs
index 99b154b7d4c6fe..5c19b271bc2cbd 100644
--- a/src/libraries/System.Net.WebProxy/ref/System.Net.WebProxy.cs
+++ b/src/libraries/System.Net.WebProxy/ref/System.Net.WebProxy.cs
@@ -18,13 +18,13 @@ public WebProxy() { }
protected WebProxy(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { }
public WebProxy(string? Address) { }
public WebProxy(string? Address, bool BypassOnLocal) { }
- public WebProxy(string? Address, bool BypassOnLocal, string[]? BypassList) { }
- public WebProxy(string? Address, bool BypassOnLocal, string[]? BypassList, System.Net.ICredentials? Credentials) { }
+ public WebProxy(string? Address, bool BypassOnLocal, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.CultureInvariant)] string[]? BypassList) { }
+ public WebProxy(string? Address, bool BypassOnLocal, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.CultureInvariant)] string[]? BypassList, System.Net.ICredentials? Credentials) { }
public WebProxy(string Host, int Port) { }
public WebProxy(System.Uri? Address) { }
public WebProxy(System.Uri? Address, bool BypassOnLocal) { }
- public WebProxy(System.Uri? Address, bool BypassOnLocal, string[]? BypassList) { }
- public WebProxy(System.Uri? Address, bool BypassOnLocal, string[]? BypassList, System.Net.ICredentials? Credentials) { }
+ public WebProxy(System.Uri? Address, bool BypassOnLocal, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.CultureInvariant)] string[]? BypassList) { }
+ public WebProxy(System.Uri? Address, bool BypassOnLocal, [System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.Regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.CultureInvariant)] string[]? BypassList, System.Net.ICredentials? Credentials) { }
public System.Uri? Address { get { throw null; } set { } }
public System.Collections.ArrayList BypassArrayList { get { throw null; } }
[System.Diagnostics.CodeAnalysis.AllowNullAttribute]
diff --git a/src/libraries/System.Net.WebProxy/ref/System.Net.WebProxy.csproj b/src/libraries/System.Net.WebProxy/ref/System.Net.WebProxy.csproj
index 477ecb4cfa2a36..43de7648955007 100644
--- a/src/libraries/System.Net.WebProxy/ref/System.Net.WebProxy.csproj
+++ b/src/libraries/System.Net.WebProxy/ref/System.Net.WebProxy.csproj
@@ -11,5 +11,6 @@
+
-
\ No newline at end of file
+
diff --git a/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs b/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs
index 7e1b3fbe01f1a2..a8b9d60651d8b0 100644
--- a/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs
+++ b/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs
@@ -20,9 +20,9 @@ public WebProxy(Uri? Address) : this(Address, false, null, null) { }
public WebProxy(Uri? Address, bool BypassOnLocal) : this(Address, BypassOnLocal, null, null) { }
- public WebProxy(Uri? Address, bool BypassOnLocal, string[]? BypassList) : this(Address, BypassOnLocal, BypassList, null) { }
+ public WebProxy(Uri? Address, bool BypassOnLocal, [StringSyntax(StringSyntaxAttribute.Regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)] string[]? BypassList) : this(Address, BypassOnLocal, BypassList, null) { }
- public WebProxy(Uri? Address, bool BypassOnLocal, string[]? BypassList, ICredentials? Credentials)
+ public WebProxy(Uri? Address, bool BypassOnLocal, [StringSyntax(StringSyntaxAttribute.Regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)] string[]? BypassList, ICredentials? Credentials)
{
this.Address = Address;
this.Credentials = Credentials;
@@ -49,12 +49,12 @@ public WebProxy(string? Address, bool BypassOnLocal)
{
}
- public WebProxy(string? Address, bool BypassOnLocal, string[]? BypassList)
+ public WebProxy(string? Address, bool BypassOnLocal, [StringSyntax(StringSyntaxAttribute.Regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)] string[]? BypassList)
: this(CreateProxyUri(Address), BypassOnLocal, BypassList, null)
{
}
- public WebProxy(string? Address, bool BypassOnLocal, string[]? BypassList, ICredentials? Credentials)
+ public WebProxy(string? Address, bool BypassOnLocal, [StringSyntax(StringSyntaxAttribute.Regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)] string[]? BypassList, ICredentials? Credentials)
: this(CreateProxyUri(Address), BypassOnLocal, BypassList, Credentials)
{
}
diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 59796633cc4dba..6272743925a926 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -57,8 +57,8 @@
-
-
+
+
@@ -254,15 +254,16 @@
-
-
-
-
+
+
+
+
+
diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs
index 1783d197b8ab8d..53a7b278fd2123 100644
--- a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs
@@ -1134,7 +1134,7 @@ public static DateTime Parse(ReadOnlySpan s, IFormatProvider? provider = n
// date and optionally a time in a culture-specific or universal format.
// Leading and trailing whitespace characters are allowed.
//
- public static DateTime ParseExact(string s, string format, IFormatProvider? provider)
+ public static DateTime ParseExact(string s, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string format, IFormatProvider? provider)
{
if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
@@ -1145,7 +1145,7 @@ public static DateTime ParseExact(string s, string format, IFormatProvider? prov
// date and optionally a time in a culture-specific or universal format.
// Leading and trailing whitespace characters are allowed.
//
- public static DateTime ParseExact(string s, string format, IFormatProvider? provider, DateTimeStyles style)
+ public static DateTime ParseExact(string s, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string format, IFormatProvider? provider, DateTimeStyles style)
{
DateTimeFormatInfo.ValidateStyles(style);
if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
@@ -1153,20 +1153,20 @@ public static DateTime ParseExact(string s, string format, IFormatProvider? prov
return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style);
}
- public static DateTime ParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles style = DateTimeStyles.None)
+ public static DateTime ParseExact(ReadOnlySpan s, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles style = DateTimeStyles.None)
{
DateTimeFormatInfo.ValidateStyles(style);
return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style);
}
- public static DateTime ParseExact(string s, string[] formats, IFormatProvider? provider, DateTimeStyles style)
+ public static DateTime ParseExact(string s, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string[] formats, IFormatProvider? provider, DateTimeStyles style)
{
DateTimeFormatInfo.ValidateStyles(style);
if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
return DateTimeParse.ParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style);
}
- public static DateTime ParseExact(ReadOnlySpan s, string[] formats, IFormatProvider? provider, DateTimeStyles style = DateTimeStyles.None)
+ public static DateTime ParseExact(ReadOnlySpan s, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string[] formats, IFormatProvider? provider, DateTimeStyles style = DateTimeStyles.None)
{
DateTimeFormatInfo.ValidateStyles(style);
return DateTimeParse.ParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style);
@@ -1282,7 +1282,7 @@ public override string ToString()
return DateTimeFormat.Format(this, null, null);
}
- public string ToString(string? format)
+ public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string? format)
{
return DateTimeFormat.Format(this, format, null);
}
@@ -1292,12 +1292,12 @@ public string ToString(IFormatProvider? provider)
return DateTimeFormat.Format(this, null, provider);
}
- public string ToString(string? format, IFormatProvider? provider)
+ public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string? format, IFormatProvider? provider)
{
return DateTimeFormat.Format(this, format, provider);
}
- public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format = default, IFormatProvider? provider = null) =>
+ public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format = default, IFormatProvider? provider = null) =>
DateTimeFormat.TryFormat(this, destination, out charsWritten, format, provider);
public DateTime ToUniversalTime()
@@ -1339,7 +1339,7 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, Dat
return DateTimeParse.TryParse(s, DateTimeFormatInfo.GetInstance(provider), styles, out result);
}
- public static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(true)] string? format, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
+ public static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(true), StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string? format, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
{
DateTimeFormatInfo.ValidateStyles(style);
@@ -1352,13 +1352,13 @@ public static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(tru
return DateTimeParse.TryParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style, out result);
}
- public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
+ public static bool TryParseExact(ReadOnlySpan s, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
{
DateTimeFormatInfo.ValidateStyles(style);
return DateTimeParse.TryParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style, out result);
}
- public static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(true)] string?[]? formats, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
+ public static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(true), StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string?[]? formats, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
{
DateTimeFormatInfo.ValidateStyles(style);
@@ -1371,7 +1371,7 @@ public static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(tru
return DateTimeParse.TryParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style, out result);
}
- public static bool TryParseExact(ReadOnlySpan s, [NotNullWhen(true)] string?[]? formats, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
+ public static bool TryParseExact(ReadOnlySpan s, [NotNullWhen(true), StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string?[]? formats, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
{
DateTimeFormatInfo.ValidateStyles(style);
return DateTimeParse.TryParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style, out result);
diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs b/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs
index 1d4dc7dcfa3ffb..d0778363fb34f1 100644
--- a/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs
@@ -544,7 +544,7 @@ public static DateTimeOffset Parse(ReadOnlySpan input, IFormatProvider? fo
// date and optionally a time in a culture-specific or universal format.
// Leading and trailing whitespace characters are allowed.
//
- public static DateTimeOffset ParseExact(string input, string format, IFormatProvider? formatProvider)
+ public static DateTimeOffset ParseExact(string input, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string format, IFormatProvider? formatProvider)
{
if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
@@ -555,7 +555,7 @@ public static DateTimeOffset ParseExact(string input, string format, IFormatProv
// date and optionally a time in a culture-specific or universal format.
// Leading and trailing whitespace characters are allowed.
//
- public static DateTimeOffset ParseExact(string input, string format, IFormatProvider? formatProvider, DateTimeStyles styles)
+ public static DateTimeOffset ParseExact(string input, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string format, IFormatProvider? formatProvider, DateTimeStyles styles)
{
styles = ValidateStyles(styles, nameof(styles));
if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
@@ -569,14 +569,14 @@ public static DateTimeOffset ParseExact(string input, string format, IFormatProv
return new DateTimeOffset(dateResult.Ticks, offset);
}
- public static DateTimeOffset ParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? formatProvider, DateTimeStyles styles = DateTimeStyles.None)
+ public static DateTimeOffset ParseExact(ReadOnlySpan input, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format, IFormatProvider? formatProvider, DateTimeStyles styles = DateTimeStyles.None)
{
styles = ValidateStyles(styles, nameof(styles));
DateTime dateResult = DateTimeParse.ParseExact(input, format, DateTimeFormatInfo.GetInstance(formatProvider), styles, out TimeSpan offset);
return new DateTimeOffset(dateResult.Ticks, offset);
}
- public static DateTimeOffset ParseExact(string input, string[] formats, IFormatProvider? formatProvider, DateTimeStyles styles)
+ public static DateTimeOffset ParseExact(string input, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string[] formats, IFormatProvider? formatProvider, DateTimeStyles styles)
{
styles = ValidateStyles(styles, nameof(styles));
if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
@@ -589,7 +589,7 @@ public static DateTimeOffset ParseExact(string input, string[] formats, IFormatP
return new DateTimeOffset(dateResult.Ticks, offset);
}
- public static DateTimeOffset ParseExact(ReadOnlySpan input, string[] formats, IFormatProvider? formatProvider, DateTimeStyles styles = DateTimeStyles.None)
+ public static DateTimeOffset ParseExact(ReadOnlySpan input, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string[] formats, IFormatProvider? formatProvider, DateTimeStyles styles = DateTimeStyles.None)
{
styles = ValidateStyles(styles, nameof(styles));
DateTime dateResult = DateTimeParse.ParseExactMultiple(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles, out TimeSpan offset);
@@ -658,16 +658,16 @@ private static DateTimeOffset ToLocalTime(DateTime utcDateTime, bool throwOnOver
public override string ToString() =>
DateTimeFormat.Format(ClockDateTime, null, null, Offset);
- public string ToString(string? format) =>
+ public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string? format) =>
DateTimeFormat.Format(ClockDateTime, format, null, Offset);
public string ToString(IFormatProvider? formatProvider) =>
DateTimeFormat.Format(ClockDateTime, null, formatProvider, Offset);
- public string ToString(string? format, IFormatProvider? formatProvider) =>
+ public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string? format, IFormatProvider? formatProvider) =>
DateTimeFormat.Format(ClockDateTime, format, formatProvider, Offset);
- public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format = default, IFormatProvider? formatProvider = null) =>
+ public bool TryFormat(Span destination, out int charsWritten, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format = default, IFormatProvider? formatProvider = null) =>
DateTimeFormat.TryFormat(ClockDateTime, destination, out charsWritten, format, formatProvider, Offset);
public DateTimeOffset ToUniversalTime() =>
@@ -717,7 +717,7 @@ public static bool TryParse(ReadOnlySpan input, IFormatProvider? formatPro
return parsed;
}
- public static bool TryParseExact([NotNullWhen(true)] string? input, [NotNullWhen(true)] string? format, IFormatProvider? formatProvider, DateTimeStyles styles,
+ public static bool TryParseExact([NotNullWhen(true)] string? input, [NotNullWhen(true), StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string? format, IFormatProvider? formatProvider, DateTimeStyles styles,
out DateTimeOffset result)
{
styles = ValidateStyles(styles, nameof(styles));
@@ -738,7 +738,7 @@ public static bool TryParseExact([NotNullWhen(true)] string? input, [NotNullWhen
}
public static bool TryParseExact(
- ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? formatProvider, DateTimeStyles styles, out DateTimeOffset result)
+ ReadOnlySpan input, [StringSyntax(StringSyntaxAttribute.DateTimeFormat)] ReadOnlySpan format, IFormatProvider? formatProvider, DateTimeStyles styles, out DateTimeOffset result)
{
styles = ValidateStyles(styles, nameof(styles));
bool parsed = DateTimeParse.TryParseExact(input, format, DateTimeFormatInfo.GetInstance(formatProvider), styles, out DateTime dateResult, out TimeSpan offset);
@@ -746,7 +746,7 @@ public static bool TryParseExact(
return parsed;
}
- public static bool TryParseExact([NotNullWhen(true)] string? input, [NotNullWhen(true)] string?[]? formats, IFormatProvider? formatProvider, DateTimeStyles styles,
+ public static bool TryParseExact([NotNullWhen(true)] string? input, [NotNullWhen(true), StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string?[]? formats, IFormatProvider? formatProvider, DateTimeStyles styles,
out DateTimeOffset result)
{
styles = ValidateStyles(styles, nameof(styles));
@@ -767,7 +767,7 @@ public static bool TryParseExact([NotNullWhen(true)] string? input, [NotNullWhen
}
public static bool TryParseExact(
- ReadOnlySpan input, [NotNullWhen(true)] string?[]? formats, IFormatProvider? formatProvider, DateTimeStyles styles, out DateTimeOffset result)
+ ReadOnlySpan input, [NotNullWhen(true), StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string?[]? formats, IFormatProvider? formatProvider, DateTimeStyles styles, out DateTimeOffset result)
{
styles = ValidateStyles(styles, nameof(styles));
bool parsed = DateTimeParse.TryParseExactMultiple(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles, out DateTime dateResult, out TimeSpan offset);
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/StringSyntaxAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/StringSyntaxAttribute.cs
new file mode 100644
index 00000000000000..5b9dbda76e5f13
--- /dev/null
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/StringSyntaxAttribute.cs
@@ -0,0 +1,46 @@
+// 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
+{
+ /// Specifies the syntax used in a string.
+ [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class StringSyntaxAttribute : Attribute
+ {
+ /// Initializes the with the identifier of the syntax used.
+ /// The syntax identifier.
+ public StringSyntaxAttribute(string syntax)
+ {
+ Syntax = syntax;
+ Arguments = Array.Empty