473,507 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading values from NameObjectCollectionBase

I've written some code that reads the names and values from a
Collections.Specialized.NameValueCollection and displays them on the screen.

However, I'd ideally like to change this code so that it runs against the
abstract Collections.Specialized.NameObjectCollectionBase class, so that all
collections that derive from this base class (which includes
NameValueCollection) will work with my code.

I can extract the keys that have been used to add items to the collections
using the Keys() property which is implemented in the base class, but there
is no similar method to extract the values that are associated with the
keys. As the class appears by definition to hold matching pairs of names
(keys) and values, I would have thought there would be a way to obtain the
values themselves.

Can anyone shed any light on this?

Thanks in advance,

--

(O)enone
Jun 3 '07 #1
2 1115

"(O)enone" <oe****@nowhere.comwrote in message
news:N5****************@newsfe3-gui.ntli.net...
I've written some code that reads the names and values from a
Collections.Specialized.NameValueCollection and displays them on the
screen.

However, I'd ideally like to change this code so that it runs against the
abstract Collections.Specialized.NameObjectCollectionBase class, so that
all collections that derive from this base class (which includes
NameValueCollection) will work with my code.

I can extract the keys that have been used to add items to the collections
using the Keys() property which is implemented in the base class, but
there is no similar method to extract the values that are associated with
the keys. As the class appears by definition to hold matching pairs of
names (keys) and values, I would have thought there would be a way to
obtain the values themselves.

Can anyone shed any light on this?

Thanks in advance,

--

(O)enone
Not very well named but the BaseGet function will take the key or an integer
as a parameter and return the value as an object.

Hope this helps.

Lloyd Sheen

Jun 3 '07 #2
Lloyd Sheen wrote:
Not very well named but the BaseGet function will take the key or an
integer as a parameter and return the value as an object.
Thanks for your assistance, Lloyd.

I settled on BaseGetAllKeys and BaseGetAllValues in the end to get the keys
and values for the whole collection in one go.

However, these are both protected members, and so the only way I can get
into them is to use reflection to identify the members and then Invoke them.
It works (at least with all the inherited object types I've tested with),
but it's pretty nasty and hacky. Is there a cleaner way that I could access
those members than this?

Thanks,

--

(O)enone
Jun 3 '07 #3

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

Similar topics

2
1787
by: Billy Jacobs | last post by:
I am getting an error saying: Public Method BaseGet not found on Type 'clsRunCollection'. The error occurs on the call to Public Property Run. If I change the parameter to an integer it works...
1
2198
by: Rein Petersen | last post by:
Hi Everyone! I hope someone may have experience serializing a NameObjectCollectionBase (System.Collections.Specialized) and can advise me as to why I receive this error (below) when I try to...
3
4381
by: William Stacey [MVP] | last post by:
What is the deal with NameObjectCollectionBase? It allows duplication keys to be added to the hashtable using System; using System.Collections; using System.Collections.Specialized; ...
1
3407
by: Mark Overstreet | last post by:
Hi, I have several custom collections that inherit from System.Collections.Specialized.NameObjectCollectionBase and I want to serialize and deserialize with the XMLSerializer object. This works...
2
1975
by: Mark Overstreet | last post by:
I am writing custom collections for my business objects but I need support for the foreach construct. I also need key support so I am inheriting from NameObjectCollectionBase. I need to support...
1
1367
by: V. | last post by:
Hi, I need to sort the object System.Collections.Specialized.NameObjectCollectionBase based on one property of the special object. Is there an easy way to do this? Thanks Vicky
3
1482
by: Sam Marrocco | last post by:
I've created a collection class that inherits the NameObjectCollectionBase. I'd like to add a few functions, such as being able to insert a new item at an indexed or keyed location in the...
2
1553
by: Sam Marrocco | last post by:
I've constructed a class that inherits the NameObjectCollectionBase class. All works well, but I'd like to shadow the GetEnumerator method so that it returns an actual value *instead of a...
2
1662
by: Sam Marrocco | last post by:
I've created a collection class that inherits NameObjectCollectionBase (call it MyCollection). MyCollection is declared as serializable, and serializes fine. A cursory glance into the serialized...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7110
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
7372
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...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
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...
1
5041
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...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.