Last active
August 30, 2016 19:20
-
-
Save dotnetchris/75f2cf6137b8e0e37961a3301e1dad5b to your computer and use it in GitHub Desktop.
Allows you to treat strings as case insensitive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct OrdinalIgnoreCaseString : IEquatable<OrdinalIgnoreCaseString>, IEquatable<string> { | |
string _str; | |
public OrdinalIgnoreCaseString(string str) { | |
_str = str; | |
} | |
public static implicit operator OrdinalIgnoreCaseString(string str) { | |
return new OrdinalIgnoreCaseString(str); | |
} | |
public static explicit operator string(OrdinalIgnoreCaseString str) { | |
return str._str; | |
} | |
public bool Equals(string other) { | |
return _str.Equals(other, StringComparison.OrdinalIgnoreCase); | |
} | |
public bool Equals(OrdinalIgnoreCaseString other) { | |
return _str.Equals(other._str, StringComparison.OrdinalIgnoreCase); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source @KrzysztofCwalina on https://github.com/dotnet/corefx/issues/649 figured this could be better long lived.