473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Testing a Comparer instance type

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
2 1658
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Frank Wisniewski | last post by:
Hi All, I have created my own generic comparer object which implements IComparer and uses reflection. I have tested it and it seem to work fine but I am worried about the way I did it. My goal...
3
by: MattC | last post by:
Hi, I found this code somewhere on the net and need to make some alterations. public class GenericSorter : IComparer { String sortProperty; bool sortOrder; public GenericSorter(String...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
44
by: John A. Bailo | last post by:
Dr. Dobbs has a /glowing/ article on Ruby on Rails this month. What do you guys think? Can it replace .net, php and java? And be the Open Source OOP web solution that is not bound to Sun or...
2
by: ckarbass | last post by:
I am testing a comparer class that implements IComparer. The comparer constructor takes as arguments a property field which can take on lets say roughly fifteen values. It also takes two other...
1
by: garyusenet | last post by:
My Array list contains a collection of InternetExplorer object. One of properties of this object is HWND. I'm trying to search my arraylist for the InternetExplorer object that has a certain...
3
by: Samuel R. Neff | last post by:
You can you program against generic interfaces generically? For example, how can I make the following code which works for the non-generic interface also work for the generic counterparts? ...
6
by: Tony | last post by:
Hello! My first question: I just can't figure out what is the usefulness of Comparer.Default.Compare(somestring1, somestring2); because I can just the same use...
10
by: Tony | last post by:
Hello! I'm reading in a book and this can't be correct it says. "Objects passed to Comparer.Compare() are checked to see if they support IComparable. If they do, then that implementation is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.