Skip to content

Commit 510eeb2

Browse files
author
Oren (electricessence)
committed
switched to 'is null' instead of '== null'.
1 parent cea313b commit 510eeb2

2 files changed

Lines changed: 42 additions & 42 deletions

File tree

StringBuilderExtensions.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static StringBuilder ToStringBuilder<T>(this IEnumerable<T> source, in ch
9595
/// </summary>
9696
public static StringBuilder AppendAll<T>(this StringBuilder target, IEnumerable<T> values, string separator = null)
9797
{
98-
if (target == null)
98+
if (target is null)
9999
throw new NullReferenceException();
100100
Contract.EndContractBlock();
101101

@@ -120,7 +120,7 @@ public static StringBuilder AppendAll<T>(this StringBuilder target, IEnumerable<
120120
/// </summary>
121121
public static StringBuilder AppendAll<T>(this StringBuilder target, IEnumerable<T> values, in char separator)
122122
{
123-
if (target == null)
123+
if (target is null)
124124
throw new NullReferenceException();
125125
Contract.EndContractBlock();
126126

@@ -136,9 +136,9 @@ public static StringBuilder AppendAll<T>(this StringBuilder target, IEnumerable<
136136
/// </summary>
137137
public static StringBuilder AppendWithSeparator<T>(this StringBuilder target, string separator, params T[] values)
138138
{
139-
if (target == null)
139+
if (target is null)
140140
throw new NullReferenceException();
141-
if (values == null || values.Length == 0)
141+
if (values is null || values.Length == 0)
142142
throw new ArgumentException("Parameters missing.");
143143
Contract.EndContractBlock();
144144

@@ -154,9 +154,9 @@ public static StringBuilder AppendWithSeparator<T>(this StringBuilder target, st
154154
/// </summary>
155155
public static StringBuilder AppendWithSeparator<T>(this StringBuilder target, in char separator, params T[] values)
156156
{
157-
if (target == null)
157+
if (target is null)
158158
throw new NullReferenceException();
159-
if (values == null || values.Length == 0)
159+
if (values is null || values.Length == 0)
160160
throw new ArgumentException("Parameters missing.");
161161
Contract.EndContractBlock();
162162

@@ -172,15 +172,15 @@ public static StringBuilder AppendWithSeparator<T>(this StringBuilder target, in
172172
/// </summary>
173173
public static void AppendWithSeparator<T>(this StringBuilder target, IDictionary<string, T> source, string key, string itemSeparator, string keyValueSeparator)
174174
{
175-
if (target == null)
175+
if (target is null)
176176
throw new NullReferenceException();
177-
if (source == null)
177+
if (source is null)
178178
throw new ArgumentNullException(nameof(source));
179-
if (key == null)
179+
if (key is null)
180180
throw new ArgumentNullException(nameof(key));
181-
if (itemSeparator == null)
181+
if (itemSeparator is null)
182182
throw new ArgumentNullException(nameof(itemSeparator));
183-
if (keyValueSeparator == null)
183+
if (keyValueSeparator is null)
184184
throw new ArgumentNullException(nameof(keyValueSeparator));
185185
Contract.EndContractBlock();
186186

Text.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static ReadOnlySpan<char> FirstSplit(this string source,
3434
out int nextIndex,
3535
int startIndex = 0)
3636
{
37-
if (source == null) throw new NullReferenceException();
37+
if (source is null) throw new NullReferenceException();
3838
Contract.EndContractBlock();
3939

4040
var i = source.Length == 0 ? -1 : source.IndexOf(splitCharacter, startIndex);
@@ -64,8 +64,8 @@ public static ReadOnlySpan<char> FirstSplit(this string source,
6464
int startIndex = 0,
6565
StringComparison comparisonType = StringComparison.Ordinal)
6666
{
67-
if (source == null) throw new NullReferenceException();
68-
if (splitSequence == null) throw new ArgumentNullException(nameof(splitSequence));
67+
if (source is null) throw new NullReferenceException();
68+
if (splitSequence is null) throw new ArgumentNullException(nameof(splitSequence));
6969
if (splitSequence.Length == 0)
7070
throw new ArgumentException("Cannot split using empty sequence.", nameof(splitSequence));
7171
Contract.EndContractBlock();
@@ -91,7 +91,7 @@ public static ReadOnlySpan<char> FirstSplit(this string source,
9191
public static IEnumerable<string> SplitAsEnumerable(this string source,
9292
char splitCharacter)
9393
{
94-
if (source == null) throw new NullReferenceException();
94+
if (source is null) throw new NullReferenceException();
9595
Contract.EndContractBlock();
9696

9797
return source.Length == 0
@@ -122,8 +122,8 @@ public static IEnumerable<string> SplitAsEnumerable(this string source,
122122
string splitSequence,
123123
StringComparison comparisonType = StringComparison.Ordinal)
124124
{
125-
if (source == null) throw new NullReferenceException();
126-
if (splitSequence == null) throw new ArgumentNullException(nameof(splitSequence));
125+
if (source is null) throw new NullReferenceException();
126+
if (splitSequence is null) throw new ArgumentNullException(nameof(splitSequence));
127127
if (splitSequence.Length == 0)
128128
throw new ArgumentException("Cannot split using empty sequence.", nameof(splitSequence));
129129
Contract.EndContractBlock();
@@ -153,7 +153,7 @@ IEnumerable<string> SplitAsEnumerableCore()
153153
/// <returns>The source of the string before the search string. Returns null if search string is not found.</returns>
154154
public static string BeforeFirst(this string source, string search, StringComparison comparisonType = StringComparison.Ordinal)
155155
{
156-
if (source == null)
156+
if (source is null)
157157
throw new NullReferenceException();
158158
Contract.EndContractBlock();
159159

@@ -173,7 +173,7 @@ public static string BeforeFirst(this string source, string search, StringCompar
173173
/// <returns>The source of the string after the search string. Returns null if search string is not found.</returns>
174174
public static string AfterFirst(this string source, string search, StringComparison comparisonType = StringComparison.Ordinal)
175175
{
176-
if (source == null)
176+
if (source is null)
177177
throw new NullReferenceException();
178178
Contract.EndContractBlock();
179179

@@ -193,7 +193,7 @@ public static string AfterFirst(this string source, string search, StringCompari
193193
/// <returns>The source of the string before the search string. Returns null if search string is not found.</returns>
194194
public static string BeforeLast(this string source, string search, StringComparison comparisonType = StringComparison.Ordinal)
195195
{
196-
if (source == null)
196+
if (source is null)
197197
throw new NullReferenceException();
198198
Contract.EndContractBlock();
199199

@@ -213,7 +213,7 @@ public static string BeforeLast(this string source, string search, StringCompari
213213
/// <returns>The source of the string after the search string. Returns null if search string is not found.</returns>
214214
public static string AfterLast(this string source, string search, StringComparison comparisonType = StringComparison.Ordinal)
215215
{
216-
if (source == null)
216+
if (source is null)
217217
throw new NullReferenceException();
218218
Contract.EndContractBlock();
219219

@@ -361,7 +361,7 @@ public static ReadOnlySpan<char> AfterLast(this in ReadOnlySpan<char> source,
361361
/// </summary>
362362
public static string ToTitleCase(this string source)
363363
{
364-
if (source == null)
364+
if (source is null)
365365
throw new NullReferenceException();
366366
Contract.EndContractBlock();
367367

@@ -374,7 +374,7 @@ public static string ToTitleCase(this string source)
374374

375375
public static bool IsAnyNullOrWhiteSpace(params string[] values)
376376
{
377-
if (values == null || values.Length == 0)
377+
if (values is null || values.Length == 0)
378378
return false;
379379

380380
return values.Any(string.IsNullOrWhiteSpace);
@@ -412,7 +412,7 @@ public static string ToNullIfWhiteSpace(this string value, bool trim = false)
412412
/// <param name="format">The format string.</param>
413413
public static string ToFormat(this string value, string format = null)
414414
=> string.IsNullOrWhiteSpace(value) ? string.Empty
415-
: (format == null ? value : string.Format(format, value));
415+
: (format is null ? value : string.Format(format, value));
416416

417417

418418
/// <summary>
@@ -422,8 +422,8 @@ public static string ToFormat(this string value, string format = null)
422422
/// <param name="format">The format string.</param>
423423
public static string ToFormat(this int? value, string format = null)
424424
{
425-
if (format == null) format = "{0}";
426-
return value == null ? string.Empty : string.Format(format, value.Value);
425+
if (format is null) format = "{0}";
426+
return value is null ? string.Empty : string.Format(format, value.Value);
427427
}
428428

429429
/// <summary>
@@ -433,8 +433,8 @@ public static string ToFormat(this int? value, string format = null)
433433
/// <param name="format">The format string.</param>
434434
public static string ToFormat(this short? value, string format = null)
435435
{
436-
if (format == null) format = "{0}";
437-
return value == null ? string.Empty : string.Format(format, value.Value);
436+
if (format is null) format = "{0}";
437+
return value is null ? string.Empty : string.Format(format, value.Value);
438438
}
439439

440440

@@ -451,14 +451,14 @@ public static bool IsAlphaNumeric(this string source, bool trim = false)
451451
#region Regex helper methods.
452452
public static string GetValue(this GroupCollection groups, string groupName, bool throwIfInvalid = false)
453453
{
454-
if (groups == null)
454+
if (groups is null)
455455
throw new NullReferenceException();
456-
if (groupName == null)
456+
if (groupName is null)
457457
throw new ArgumentNullException(nameof(groupName));
458458
Contract.EndContractBlock();
459459

460460
var group = groups[groupName];
461-
if (group == null)
461+
if (group is null)
462462
{
463463
if (throwIfInvalid)
464464
throw new ArgumentException();
@@ -476,7 +476,7 @@ public static string GetValue(this GroupCollection groups, string groupName, boo
476476
/// </summary>
477477
public static string ToString(this double? value, string format)
478478
{
479-
if (format == null)
479+
if (format is null)
480480
throw new ArgumentNullException(nameof(format));
481481
Contract.EndContractBlock();
482482

@@ -489,7 +489,7 @@ public static string ToString(this double? value, string format)
489489
/// </summary>
490490
public static string ToString(this float? value, string format)
491491
{
492-
if (format == null)
492+
if (format is null)
493493
throw new ArgumentNullException(nameof(format));
494494
Contract.EndContractBlock();
495495

@@ -501,7 +501,7 @@ public static string ToString(this float? value, string format)
501501
/// </summary>
502502
public static string ToString(this int? value, string format)
503503
{
504-
if (format == null)
504+
if (format is null)
505505
throw new ArgumentNullException(nameof(format));
506506
Contract.EndContractBlock();
507507

@@ -591,9 +591,9 @@ public static string ToMetricString(this int number)
591591
public static readonly Regex WHITESPACE = new Regex(@"\s+");
592592
public static string ReplaceWhiteSpace(this string source, string replace = " ")
593593
{
594-
if (source == null)
594+
if (source is null)
595595
throw new NullReferenceException();
596-
if (replace == null)
596+
if (replace is null)
597597
throw new ArgumentNullException(nameof(replace));
598598
Contract.EndContractBlock();
599599

@@ -602,11 +602,11 @@ public static string ReplaceWhiteSpace(this string source, string replace = " ")
602602

603603
public static string TrimStart(this string source, string pattern)
604604
{
605-
if (source == null)
605+
if (source is null)
606606
throw new NullReferenceException();
607607
Contract.EndContractBlock();
608608

609-
if (pattern == null)
609+
if (pattern is null)
610610
return source.TrimStart();
611611

612612
if (pattern == string.Empty)
@@ -619,11 +619,11 @@ public static string TrimStart(this string source, string pattern)
619619

620620
public static string TrimEnd(this string source, string pattern)
621621
{
622-
if (source == null)
622+
if (source is null)
623623
throw new NullReferenceException();
624624
Contract.EndContractBlock();
625625

626-
if (pattern == null)
626+
if (pattern is null)
627627
return source.TrimEnd();
628628

629629
if (pattern == string.Empty)
@@ -642,7 +642,7 @@ public static string TrimEnd(this string source, string pattern)
642642
/// </summary>
643643
public static void WriteLineNoTabs(this TextWriter writer, string s = null)
644644
{
645-
if (writer == null)
645+
if (writer is null)
646646
throw new NullReferenceException();
647647
Contract.EndContractBlock();
648648

@@ -660,7 +660,7 @@ public static void WriteLineNoTabs(this TextWriter writer, string s = null)
660660
/// <returns>The resultant string.</returns>
661661
public static string Supplant<T>(this string format, T[] values)
662662
{
663-
if (values == null)
663+
if (values is null)
664664
return format;
665665

666666
switch (values.Length)

0 commit comments

Comments
 (0)