diff options
Diffstat (limited to 'src/mscorlib/src/System/StringComparer.cs')
-rw-r--r-- | src/mscorlib/src/System/StringComparer.cs | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/mscorlib/src/System/StringComparer.cs b/src/mscorlib/src/System/StringComparer.cs index 57bdf4c6b2..02e8d71d0e 100644 --- a/src/mscorlib/src/System/StringComparer.cs +++ b/src/mscorlib/src/System/StringComparer.cs @@ -62,9 +62,31 @@ namespace System { } } + // Convert a StringComparison to a StringComparer + public static StringComparer FromComparison(StringComparison comparisonType) + { + switch (comparisonType) + { + case StringComparison.CurrentCulture: + return CurrentCulture; + case StringComparison.CurrentCultureIgnoreCase: + return CurrentCultureIgnoreCase; + case StringComparison.InvariantCulture: + return InvariantCulture; + case StringComparison.InvariantCultureIgnoreCase: + return InvariantCultureIgnoreCase; + case StringComparison.Ordinal: + return Ordinal; + case StringComparison.OrdinalIgnoreCase: + return OrdinalIgnoreCase; + default: + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); + } + } + public static StringComparer Create(CultureInfo culture, bool ignoreCase) { if( culture == null) { - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); } Contract.Ensures(Contract.Result<StringComparer>() != null); Contract.EndContractBlock(); @@ -110,7 +132,7 @@ namespace System { public int GetHashCode(object obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); @@ -161,7 +183,7 @@ namespace System { public override int GetHashCode(string obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); @@ -229,7 +251,7 @@ namespace System { public override int GetHashCode(string obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); @@ -311,7 +333,7 @@ namespace System { public override int GetHashCode(string obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); @@ -385,10 +407,9 @@ namespace System { return x.Equals(y); } - [System.Security.SecuritySafeCritical] public override int GetHashCode(string obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); |