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
:)