P
PIEBALD
Not really a C#-specific comment, more general .net observations.
1) A while back I found the need to determine whether or not a particular
StringComparer was case-insensitive. The best way I found was to use
Reflection to access the private _ignoreCase field, which I'd rather not do.
It seems to me that a public readonly property would be helpful. (Better yet,
it should probably have a CompareOptions)
2) The CompareInfo.Compare method only works on strings (or substrings), not
individual characters. It seems that it must compare one character at a time,
why not expose a method to allow that?
3) HashSet<char> has a constructor that can be passed an
IEqualityComparer<char>, but there's none built-in. I'm not complaining,
really, but it seems to me that if you're going to write a StringComparer it
should be based on a CharComparer.
So I spent this evening writing my own CharComparer, trying to stay close to
the pattern of StringComparer, but I added public readonly fields to hold the
CompareInfo and CompareOptions.
The main downside is that it has to wrap the characters in strings to use
CompareInfo.Compare, which seems needlessly wasteful.
Or am I missing something?
1) A while back I found the need to determine whether or not a particular
StringComparer was case-insensitive. The best way I found was to use
Reflection to access the private _ignoreCase field, which I'd rather not do.
It seems to me that a public readonly property would be helpful. (Better yet,
it should probably have a CompareOptions)
2) The CompareInfo.Compare method only works on strings (or substrings), not
individual characters. It seems that it must compare one character at a time,
why not expose a method to allow that?
3) HashSet<char> has a constructor that can be passed an
IEqualityComparer<char>, but there's none built-in. I'm not complaining,
really, but it seems to me that if you're going to write a StringComparer it
should be based on a CharComparer.
So I spent this evening writing my own CharComparer, trying to stay close to
the pattern of StringComparer, but I added public readonly fields to hold the
CompareInfo and CompareOptions.
The main downside is that it has to wrap the characters in strings to use
CompareInfo.Compare, which seems needlessly wasteful.
Or am I missing something?