473,407 Members | 2,629 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,407 software developers and data experts.

Generics Dictionary - modify ContainsKey and Key Lookup

Hi

I have a class that inherits from Generics Dictionary
The string that is used for the key is passed thru-out my pgm and sometimes
it has modifiers added to the key string that are used in the system.

The problem is now I have to strip the modifer to lookup in the Dictionary
and I have to copy this code whenever I need to lookup the key or if more
modifers are added

Is there someway for me to override the way the Dictionary Lookups keys
so I can write the code to strip the modifer in one place so when I do a
ContainsKey
of this[sFileName][sKey] - if will look for key and if not found try to find
again after replace????

Thanks

if (this[sFileName].ContainsKey(sKey))
{
return (this[sFileName][sKey].Info);
}
else if (this[sFileName].ContainsKey(sKey.Replace("#","")))
{
return (this[sFileName][sKey.Replace("#","")]Info);
}
else if (this[sFileName].ContainsKey(sKey.Replace("^","")))
{
return (this[sFileName][sKey.Replace("^","")]Info);
}
Oct 29 '07 #1
2 3425
You can implement the IEqualityComparer<Tinterface, implementing the
Equals and GetHashCode methods to work on the modified keys for comparison,
and then pass that implementation to the dictionary.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"sippyuconn" <si********@newsgroup.nospamwrote in message
news:85**********************************@microsof t.com...
Hi

I have a class that inherits from Generics Dictionary
The string that is used for the key is passed thru-out my pgm and
sometimes
it has modifiers added to the key string that are used in the system.

The problem is now I have to strip the modifer to lookup in the Dictionary
and I have to copy this code whenever I need to lookup the key or if more
modifers are added

Is there someway for me to override the way the Dictionary Lookups keys
so I can write the code to strip the modifer in one place so when I do a
ContainsKey
of this[sFileName][sKey] - if will look for key and if not found try to
find
again after replace????

Thanks

if (this[sFileName].ContainsKey(sKey))
{
return (this[sFileName][sKey].Info);
}
else if (this[sFileName].ContainsKey(sKey.Replace("#","")))
{
return (this[sFileName][sKey.Replace("#","")]Info);
}
else if (this[sFileName].ContainsKey(sKey.Replace("^","")))
{
return (this[sFileName][sKey.Replace("^","")]Info);
}

Oct 29 '07 #2
Hi,

Have you reviewed Nicholas Paldino [.NET/C# MVP]'s reply to you? Does it
resolve your question? If you still need any help, please feel free to
feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brian Richards | last post by:
I'm experiencing some wierd behavior with a Dictionary<T,U> class using foreach loops, such that the Key returned in the foreach is not contained in the dictionary. code: Dictionary<A, B>...
0
by: Frank | last post by:
I'm using VB in ASP.NET 2.0. I've created a dictionary with a custom key that contains 2 integers as properties. The key is in the dictionary, but when I do a ContainsKey(mykey) it always returns...
3
by: craigkenisston | last post by:
I want to use Dictionary class like this: textboxM.Text = oMyDict.GetValue("textboxM"); textboxN.Text = oMyDict.GetValue("textboxN"); Where my dictionary contains the list of values for my...
5
by: Stefano Peduzzi | last post by:
Hi, I'm building an application where I've defined a custom class Customer. Customer can have many phones (defined by phoneType and phoneNumber). I want to check that a phoneNumber is not already...
0
by: xpding | last post by:
Hello, I have a class MyEmbededList contains a generic dictionary, the value field is actually the MyEmbededList type as well. There is another class need to access and manipulate a list of...
18
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've a question regarding dictionaries. I have an array elements that I created, and I'm trying to sort those elements into various sections. Here's the template of my...
3
by: Phil Sandler | last post by:
All, I have a situation where I need a List<stringthat performs like a generic dictionary (Dictionary<string, string>). Essentially, I just need the key, not the value, so I want to use as...
8
by: Bob Altman | last post by:
Hi all, I'm trying to do something that should be really easy, but I can't think of an obvious way to do it. I have a dictionary whose value is a "value type" (as opposed to a reference type --...
3
by: Dmitry Nogin | last post by:
Hi, I would like to use dictionaries to implement my property value storing mechanics. (I have a lot but many of them are just about to keep <nullmost of the time, so it might save a lot of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.