11namespace Schema . NET
22{
33 using System ;
4+ using System . Diagnostics . CodeAnalysis ;
45
56 /// <summary>
67 /// Helper for parsing strings into <see cref="DateTime"/> or <see cref="DateTimeOffset"/>
@@ -45,7 +46,12 @@ public static bool ContainsTimeOffset(string? input)
4546 /// <param name="input">The input string</param>
4647 /// <param name="result">The result date and time</param>
4748 /// <returns>True if the input string was able to be parsed into a <see cref="DateTime"/></returns>
48- public static bool TryParseMSDateTime ( string ? input , out DateTime result )
49+ public static bool TryParseMSDateTime (
50+ #if NETCOREAPP3_1_OR_GREATER
51+ [ NotNullWhen ( true ) ]
52+ #endif
53+ string ? input ,
54+ out DateTime result )
4955 {
5056 if ( input is not null &&
5157 input . StartsWith ( MSDateStringStart , StringComparison . Ordinal ) &&
@@ -54,7 +60,7 @@ public static bool TryParseMSDateTime(string? input, out DateTime result)
5460 var dateTimeStartIndex = MSDateStringStart . Length ;
5561 var dateTimeLength = input . IndexOf ( MSDateStringEnd , StringComparison . Ordinal ) - dateTimeStartIndex ;
5662
57- #if NETCOREAPP3_1
63+ #if NETCOREAPP3_1_OR_GREATER
5864 var timeValue = input . AsSpan ( ) . Slice ( dateTimeStartIndex , dateTimeLength ) ;
5965#else
6066 var timeValue = input . Substring ( dateTimeStartIndex , dateTimeLength ) ;
@@ -77,7 +83,12 @@ public static bool TryParseMSDateTime(string? input, out DateTime result)
7783 /// <param name="input">The input string</param>
7884 /// <param name="result">The result date and time with offset</param>
7985 /// <returns>True if the input string was able to be parsed into a <see cref="DateTimeOffset"/></returns>
80- public static bool TryParseMSDateTimeOffset ( string ? input , out DateTimeOffset result )
86+ public static bool TryParseMSDateTimeOffset (
87+ #if NETCOREAPP3_1_OR_GREATER
88+ [ NotNullWhen ( true ) ]
89+ #endif
90+ string ? input ,
91+ out DateTimeOffset result )
8192 {
8293 if ( input is not null &&
8394 input . StartsWith ( MSDateStringStart , StringComparison . Ordinal ) &&
@@ -88,7 +99,7 @@ public static bool TryParseMSDateTimeOffset(string? input, out DateTimeOffset re
8899 var dateTimeLength = offsetIndex - dateTimeStartIndex ;
89100 var offsetLength = input . IndexOf ( MSDateStringEnd , offsetIndex , StringComparison . Ordinal ) - offsetIndex ;
90101
91- #if NETCOREAPP3_1
102+ #if NETCOREAPP3_1_OR_GREATER
92103 var timeValue = input . AsSpan ( ) . Slice ( dateTimeStartIndex , dateTimeLength ) ;
93104 var offsetType = input . AsSpan ( ) . Slice ( offsetIndex , 1 ) ;
94105 var offsetValue = input . AsSpan ( ) . Slice ( offsetIndex + 1 , offsetLength - 1 ) ;
0 commit comments