@@ -1134,7 +1134,7 @@ public static DateTime Parse(ReadOnlySpan<char> s, IFormatProvider? provider = n
1134
1134
// date and optionally a time in a culture-specific or universal format.
1135
1135
// Leading and trailing whitespace characters are allowed.
1136
1136
//
1137
- public static DateTime ParseExact ( string s , string format , IFormatProvider ? provider )
1137
+ public static DateTime ParseExact ( string s , [ StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] string format , IFormatProvider ? provider )
1138
1138
{
1139
1139
if ( s == null ) ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . s ) ;
1140
1140
if ( format == null ) ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . format ) ;
@@ -1145,28 +1145,28 @@ public static DateTime ParseExact(string s, string format, IFormatProvider? prov
1145
1145
// date and optionally a time in a culture-specific or universal format.
1146
1146
// Leading and trailing whitespace characters are allowed.
1147
1147
//
1148
- public static DateTime ParseExact ( string s , string format , IFormatProvider ? provider , DateTimeStyles style )
1148
+ public static DateTime ParseExact ( string s , [ StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] string format , IFormatProvider ? provider , DateTimeStyles style )
1149
1149
{
1150
1150
DateTimeFormatInfo . ValidateStyles ( style ) ;
1151
1151
if ( s == null ) ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . s ) ;
1152
1152
if ( format == null ) ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . format ) ;
1153
1153
return DateTimeParse . ParseExact ( s , format , DateTimeFormatInfo . GetInstance ( provider ) , style ) ;
1154
1154
}
1155
1155
1156
- public static DateTime ParseExact ( ReadOnlySpan < char > s , ReadOnlySpan < char > format , IFormatProvider ? provider , DateTimeStyles style = DateTimeStyles . None )
1156
+ public static DateTime ParseExact ( ReadOnlySpan < char > s , [ StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] ReadOnlySpan < char > format , IFormatProvider ? provider , DateTimeStyles style = DateTimeStyles . None )
1157
1157
{
1158
1158
DateTimeFormatInfo . ValidateStyles ( style ) ;
1159
1159
return DateTimeParse . ParseExact ( s , format , DateTimeFormatInfo . GetInstance ( provider ) , style ) ;
1160
1160
}
1161
1161
1162
- public static DateTime ParseExact ( string s , string [ ] formats , IFormatProvider ? provider , DateTimeStyles style )
1162
+ public static DateTime ParseExact ( string s , [ StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] string [ ] formats , IFormatProvider ? provider , DateTimeStyles style )
1163
1163
{
1164
1164
DateTimeFormatInfo . ValidateStyles ( style ) ;
1165
1165
if ( s == null ) ThrowHelper . ThrowArgumentNullException ( ExceptionArgument . s ) ;
1166
1166
return DateTimeParse . ParseExactMultiple ( s , formats , DateTimeFormatInfo . GetInstance ( provider ) , style ) ;
1167
1167
}
1168
1168
1169
- public static DateTime ParseExact ( ReadOnlySpan < char > s , string [ ] formats , IFormatProvider ? provider , DateTimeStyles style = DateTimeStyles . None )
1169
+ public static DateTime ParseExact ( ReadOnlySpan < char > s , [ StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] string [ ] formats , IFormatProvider ? provider , DateTimeStyles style = DateTimeStyles . None )
1170
1170
{
1171
1171
DateTimeFormatInfo . ValidateStyles ( style ) ;
1172
1172
return DateTimeParse . ParseExactMultiple ( s , formats , DateTimeFormatInfo . GetInstance ( provider ) , style ) ;
@@ -1282,7 +1282,7 @@ public override string ToString()
1282
1282
return DateTimeFormat . Format ( this , null , null ) ;
1283
1283
}
1284
1284
1285
- public string ToString ( string ? format )
1285
+ public string ToString ( [ StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] string ? format )
1286
1286
{
1287
1287
return DateTimeFormat . Format ( this , format , null ) ;
1288
1288
}
@@ -1292,12 +1292,12 @@ public string ToString(IFormatProvider? provider)
1292
1292
return DateTimeFormat . Format ( this , null , provider ) ;
1293
1293
}
1294
1294
1295
- public string ToString ( string ? format , IFormatProvider ? provider )
1295
+ public string ToString ( [ StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] string ? format , IFormatProvider ? provider )
1296
1296
{
1297
1297
return DateTimeFormat . Format ( this , format , provider ) ;
1298
1298
}
1299
1299
1300
- public bool TryFormat ( Span < char > destination , out int charsWritten , ReadOnlySpan < char > format = default , IFormatProvider ? provider = null ) =>
1300
+ public bool TryFormat ( Span < char > destination , out int charsWritten , [ StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] ReadOnlySpan < char > format = default , IFormatProvider ? provider = null ) =>
1301
1301
DateTimeFormat . TryFormat ( this , destination , out charsWritten , format , provider ) ;
1302
1302
1303
1303
public DateTime ToUniversalTime ( )
@@ -1339,7 +1339,7 @@ public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, Dat
1339
1339
return DateTimeParse . TryParse ( s , DateTimeFormatInfo . GetInstance ( provider ) , styles , out result ) ;
1340
1340
}
1341
1341
1342
- public static bool TryParseExact ( [ NotNullWhen ( true ) ] string ? s , [ NotNullWhen ( true ) ] string ? format , IFormatProvider ? provider , DateTimeStyles style , out DateTime result )
1342
+ public static bool TryParseExact ( [ NotNullWhen ( true ) ] string ? s , [ NotNullWhen ( true ) , StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] string ? format , IFormatProvider ? provider , DateTimeStyles style , out DateTime result )
1343
1343
{
1344
1344
DateTimeFormatInfo . ValidateStyles ( style ) ;
1345
1345
@@ -1352,13 +1352,13 @@ public static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(tru
1352
1352
return DateTimeParse . TryParseExact ( s , format , DateTimeFormatInfo . GetInstance ( provider ) , style , out result ) ;
1353
1353
}
1354
1354
1355
- public static bool TryParseExact ( ReadOnlySpan < char > s , ReadOnlySpan < char > format , IFormatProvider ? provider , DateTimeStyles style , out DateTime result )
1355
+ public static bool TryParseExact ( ReadOnlySpan < char > s , [ StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] ReadOnlySpan < char > format , IFormatProvider ? provider , DateTimeStyles style , out DateTime result )
1356
1356
{
1357
1357
DateTimeFormatInfo . ValidateStyles ( style ) ;
1358
1358
return DateTimeParse . TryParseExact ( s , format , DateTimeFormatInfo . GetInstance ( provider ) , style , out result ) ;
1359
1359
}
1360
1360
1361
- public static bool TryParseExact ( [ NotNullWhen ( true ) ] string ? s , [ NotNullWhen ( true ) ] string ? [ ] ? formats , IFormatProvider ? provider , DateTimeStyles style , out DateTime result )
1361
+ public static bool TryParseExact ( [ NotNullWhen ( true ) ] string ? s , [ NotNullWhen ( true ) , StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] string ? [ ] ? formats , IFormatProvider ? provider , DateTimeStyles style , out DateTime result )
1362
1362
{
1363
1363
DateTimeFormatInfo . ValidateStyles ( style ) ;
1364
1364
@@ -1371,7 +1371,7 @@ public static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(tru
1371
1371
return DateTimeParse . TryParseExactMultiple ( s , formats , DateTimeFormatInfo . GetInstance ( provider ) , style , out result ) ;
1372
1372
}
1373
1373
1374
- public static bool TryParseExact ( ReadOnlySpan < char > s , [ NotNullWhen ( true ) ] string ? [ ] ? formats , IFormatProvider ? provider , DateTimeStyles style , out DateTime result )
1374
+ public static bool TryParseExact ( ReadOnlySpan < char > s , [ NotNullWhen ( true ) , StringSyntax ( StringSyntaxAttribute . DateTimeFormat ) ] string ? [ ] ? formats , IFormatProvider ? provider , DateTimeStyles style , out DateTime result )
1375
1375
{
1376
1376
DateTimeFormatInfo . ValidateStyles ( style ) ;
1377
1377
return DateTimeParse . TryParseExactMultiple ( s , formats , DateTimeFormatInfo . GetInstance ( provider ) , style , out result ) ;
0 commit comments