By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,009 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,009 IT Pros & Developers. It's quick & easy.

Testing a Comparer instance type

P: n/a
Hello!

I am trying to find a way to deal with Windows' case insensitivity
without just forcing everything lowercase. While I am open to criticism
on my method - my question relates to the fourth to bottom line (not
including curly braces) on the bottom - testing to see if the Comparer
is not StringComparer.OrdinalIgnoreCase

My concern is eventually when I decide to serialize these to files, to
store persistant data, that somehow - either through usage,
implementation or design change that the type of the StringComparer will
get changed.

For simplicity sake, I have removed error handling and warnings.

public abstract class Task{ //A class to facilitate error handling and
progress for blocking calls
public Dictionary<string, Dictionary<string, string>data;
protected abstract void execute();
public void ExecuteInBlockingCall(){
execute();
}
}

public class InitializeCaseInsensitiveFileStorage : Task { //prepare
dictionaries to hold case insensitive local files
protected override void execute() {
string[] alwaysDelete = {"new_dest", "new_hash", "new_date"};
string[] alwaysCheck = {"old_date", "old_hash", "old_dest"};
foreach(string i in alwaysDelete){
if(data.ContainsKey(i))
data.Remove(i);
data.Add(i, new Dictionary<string,
string>(StringComparer.OrdinalIgnoreCase));
}
foreach(string i in alwaysCheck)
if(!data.ContainsKey(i))
data.Add(i, new Dictionary<string,
string>(StringComparer.OrdinalIgnoreCase));
else if(data[i].Comparer!=StringComparer.OrdinalIgnoreCase){
data.Remove(i);
data.Add(i, new Dictionary<string,
string>(StringComparer.OrdinalIgnoreCase));
}
}
Is data[i].Comparer!=StringComparer.OrdinalIgnoreCase a reasonable way
to check and make sure that we are using the expected string comparer?
Will this work even after serialization? (I will add [Serializable]
tags and have this handled automatically)

Thank you

--
LTP

:)
Jan 2 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

if(data[i].Comparer!=StringComparer.OrdinalIgnoreCase){
The above line might be incorrect, according to MSDN it returns an instance
of an anonymous class. It does not says if it will ALWAYS return the same
isntance.


Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Jan 2 '08 #2

P: n/a
Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,

>if(data[i].Comparer!=StringComparer.OrdinalIgnoreCase){

The above line might be incorrect, according to MSDN it returns an instance
of an anonymous class. It does not says if it will ALWAYS return the same
isntance.
Ok.

This is what I was worried about

Is there anyway I can test it short of adding something to the
dictionary and the making sure I find it again with capitalization
changed? I'm trying to avoud *that* method if possible.

--
LTP

:)
Jan 2 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.