@@ -151,7 +151,7 @@ IEnumerable<string> SplitAsEnumerableCore()
151151 /// <param name="search">The search string to look for. If the search is null or empty this method returns null.</param>
152152 /// <param name="comparisonType">The comparison type to use when searching.</param>
153153 /// <returns>The source of the string before the search string. Returns null if search string is not found.</returns>
154- public static string BeforeFirst ( this string source , string search , StringComparison comparisonType = StringComparison . Ordinal )
154+ public static string ? BeforeFirst ( this string source , string search , StringComparison comparisonType = StringComparison . Ordinal )
155155 {
156156 if ( source is null )
157157 throw new NullReferenceException ( ) ;
@@ -171,7 +171,7 @@ public static string BeforeFirst(this string source, string search, StringCompar
171171 /// <param name="search">The search string to look for. If the search is null or empty this method returns null.</param>
172172 /// <param name="comparisonType">The comparison type to use when searching.</param>
173173 /// <returns>The source of the string after the search string. Returns null if search string is not found.</returns>
174- public static string AfterFirst ( this string source , string search , StringComparison comparisonType = StringComparison . Ordinal )
174+ public static string ? AfterFirst ( this string source , string search , StringComparison comparisonType = StringComparison . Ordinal )
175175 {
176176 if ( source is null )
177177 throw new NullReferenceException ( ) ;
@@ -191,7 +191,7 @@ public static string AfterFirst(this string source, string search, StringCompari
191191 /// <param name="search">The search string to look for. If the search is null or empty this method returns null.</param>
192192 /// <param name="comparisonType">The comparison type to use when searching.</param>
193193 /// <returns>The source of the string before the search string. Returns null if search string is not found.</returns>
194- public static string BeforeLast ( this string source , string search , StringComparison comparisonType = StringComparison . Ordinal )
194+ public static string ? BeforeLast ( this string source , string search , StringComparison comparisonType = StringComparison . Ordinal )
195195 {
196196 if ( source is null )
197197 throw new NullReferenceException ( ) ;
@@ -211,7 +211,7 @@ public static string BeforeLast(this string source, string search, StringCompari
211211 /// <param name="search">The search string to look for. If the search is null or empty this method returns null.</param>
212212 /// <param name="comparisonType">The comparison type to use when searching.</param>
213213 /// <returns>The source of the string after the search string. Returns null if search string is not found.</returns>
214- public static string AfterLast ( this string source , string search , StringComparison comparisonType = StringComparison . Ordinal )
214+ public static string ? AfterLast ( this string source , string search , StringComparison comparisonType = StringComparison . Ordinal )
215215 {
216216 if ( source is null )
217217 throw new NullReferenceException ( ) ;
@@ -400,7 +400,7 @@ public static bool IsNullOrWhiteSpace(this string source)
400400 /// </summary>
401401 /// <param name="value">The value to be trimmed.</param>
402402 /// <param name="trim">True will trim whitespace from valid response.</param>
403- public static string ToNullIfWhiteSpace ( this string value , bool trim = false )
403+ public static string ? ToNullIfWhiteSpace ( this string value , bool trim = false )
404404 => string . IsNullOrWhiteSpace ( value ) ? null
405405 : ( trim ? value . Trim ( ) : value ) ;
406406
@@ -410,7 +410,7 @@ public static string ToNullIfWhiteSpace(this string value, bool trim = false)
410410 /// </summary>
411411 /// <param name="value">The value to be formatted.</param>
412412 /// <param name="format">The format string.</param>
413- public static string ToFormat ( this string value , string format = null )
413+ public static string ToFormat ( this string value , string ? format = null )
414414 => string . IsNullOrWhiteSpace ( value ) ? string . Empty
415415 : ( format is null ? value : string . Format ( format , value ) ) ;
416416
@@ -420,7 +420,7 @@ public static string ToFormat(this string value, string format = null)
420420 /// </summary>
421421 /// <param name="value">The value to be formatted.</param>
422422 /// <param name="format">The format string.</param>
423- public static string ToFormat ( this int ? value , string format = null )
423+ public static string ToFormat ( this int ? value , string ? format = null )
424424 {
425425 if ( format is null ) format = "{0}" ;
426426 return value is null ? string . Empty : string . Format ( format , value . Value ) ;
@@ -431,7 +431,7 @@ public static string ToFormat(this int? value, string format = null)
431431 /// </summary>
432432 /// <param name="value">The value to be formatted.</param>
433433 /// <param name="format">The format string.</param>
434- public static string ToFormat ( this short ? value , string format = null )
434+ public static string ToFormat ( this short ? value , string ? format = null )
435435 {
436436 if ( format is null ) format = "{0}" ;
437437 return value is null ? string . Empty : string . Format ( format , value . Value ) ;
@@ -449,7 +449,7 @@ public static bool IsAlphaNumeric(this string source, bool trim = false)
449449 }
450450
451451 #region Regex helper methods.
452- public static string GetValue ( this GroupCollection groups , string groupName , bool throwIfInvalid = false )
452+ public static string ? GetValue ( this GroupCollection groups , string groupName , bool throwIfInvalid = false )
453453 {
454454 if ( groups is null )
455455 throw new NullReferenceException ( ) ;
@@ -640,14 +640,12 @@ public static string TrimEnd(this string source, string pattern)
640640 /// <summary>
641641 /// Shortcut for WriteLineNoTabs on a TextWriter. Mimimcs similar classes.
642642 /// </summary>
643- public static void WriteLineNoTabs ( this TextWriter writer , string s = null )
643+ public static void WriteLineNoTabs ( this TextWriter writer , string ? s = null )
644644 {
645- if ( writer is null )
646- throw new NullReferenceException ( ) ;
645+ if ( writer is null ) throw new NullReferenceException ( ) ;
647646 Contract . EndContractBlock ( ) ;
648647
649- if ( s != null )
650- writer . Write ( s ) ;
648+ if ( s != null ) writer . Write ( s ) ;
651649 writer . Write ( NEWLINE ) ;
652650 }
653651
@@ -659,21 +657,12 @@ public static void WriteLineNoTabs(this TextWriter writer, string s = null)
659657 /// <param name="values">The values to inject.</param>
660658 /// <returns>The resultant string.</returns>
661659 public static string Supplant < T > ( this string format , T [ ] values )
662- {
663- if ( values is null )
664- return format ;
665-
666- switch ( values . Length )
660+ => values is null ? format : values . Length switch
667661 {
668- case 0 :
669- return format ;
670- case 1 :
671- return string . Format ( format , values [ 0 ] ) ;
672- default :
673- return string . Format ( format ,
674- values as object [ ] ?? values . Cast < object > ( ) . ToArray ( ) ) ;
675- }
676- }
662+ 0 => format ,
663+ 1 => string . Format ( format , values [ 0 ] ) ,
664+ _ => string . Format ( format , values as object [ ] ?? values . Cast < object > ( ) . ToArray ( ) ) ,
665+ } ;
677666
678667 }
679668}
0 commit comments