summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib/shared/System/StringComparer.cs
diff options
context:
space:
mode:
authorBen Adams <thundercat@illyriad.co.uk>2019-01-06 02:49:58 +0100
committerJan Kotas <jkotas@microsoft.com>2019-01-05 17:49:58 -0800
commitd0cdf8813ef099deec3b6940e34f20d1bba054b8 (patch)
treebd0f4eb03f4a5f09e3c9970c320988e80c076c3f /src/System.Private.CoreLib/shared/System/StringComparer.cs
parent110835b1b818b333f27ab76db3f223a03027698a (diff)
downloadcoreclr-d0cdf8813ef099deec3b6940e34f20d1bba054b8.tar.gz
coreclr-d0cdf8813ef099deec3b6940e34f20d1bba054b8.tar.bz2
coreclr-d0cdf8813ef099deec3b6940e34f20d1bba054b8.zip
(C#7) Use pattern matching `is` rather than `as` with null check (#21828)
* Use pattern matching `is` rather than `as` with null check
Diffstat (limited to 'src/System.Private.CoreLib/shared/System/StringComparer.cs')
-rw-r--r--src/System.Private.CoreLib/shared/System/StringComparer.cs24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/System.Private.CoreLib/shared/System/StringComparer.cs b/src/System.Private.CoreLib/shared/System/StringComparer.cs
index e4378c5efa..8fab833592 100644
--- a/src/System.Private.CoreLib/shared/System/StringComparer.cs
+++ b/src/System.Private.CoreLib/shared/System/StringComparer.cs
@@ -114,18 +114,15 @@ namespace System
if (x == null) return -1;
if (y == null) return 1;
- string sa = x as string;
- if (sa != null)
+ if (x is string sa)
{
- string sb = y as string;
- if (sb != null)
+ if (y is string sb)
{
return Compare(sa, sb);
}
}
- IComparable ia = x as IComparable;
- if (ia != null)
+ if (x is IComparable ia)
{
return ia.CompareTo(y);
}
@@ -138,11 +135,9 @@ namespace System
if (x == y) return true;
if (x == null || y == null) return false;
- string sa = x as string;
- if (sa != null)
+ if (x is string sa)
{
- string sb = y as string;
- if (sb != null)
+ if (y is string sb)
{
return Equals(sa, sb);
}
@@ -157,8 +152,7 @@ namespace System
throw new ArgumentNullException(nameof(obj));
}
- string s = obj as string;
- if (s != null)
+ if (obj is string s)
{
return GetHashCode(s);
}
@@ -232,9 +226,8 @@ namespace System
// Equals method for the comparer itself.
public override bool Equals(object obj)
{
- CultureAwareComparer comparer = obj as CultureAwareComparer;
return
- comparer != null &&
+ obj is CultureAwareComparer comparer &&
_options == comparer._options &&
_compareInfo.Equals(comparer._compareInfo);
}
@@ -316,8 +309,7 @@ namespace System
// Equals method for the comparer itself.
public override bool Equals(object obj)
{
- OrdinalComparer comparer = obj as OrdinalComparer;
- if (comparer == null)
+ if (!(obj is OrdinalComparer comparer))
{
return false;
}