473,666 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserialize Custom Collection Extending NameObjectColle ctionBase

Hi,

I have several custom collections that inherit from
System.Collecti ons.Specialized .NameObjectColl ectionBase and I want to
serialize and deserialize with the XMLSerializer object. This works great
but my problem is that when the deserialization occurs, it uses the default
add method to add objects to the collection without adding the keys.

My question is this. Is there any way to use the XMLSerializer object to
deserialize and inform the deserialization process which attribute or element
should be considered the key and have it call a different add method with the
key? Or what approach do I have to take?

Thanks
Mark Overstreet
Nov 16 '05 #1
1 3424
Mark,

In this case, you might have to implement IXmlSerializabl e on your
class, and handle the serialization yourself, reading the associated keys,
and then adding them properly to your collection with the values.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Mark Overstreet" <Mark Ov********@disc ussions.microso ft.com> wrote in
message news:63******** *************** ***********@mic rosoft.com...
Hi,

I have several custom collections that inherit from
System.Collecti ons.Specialized .NameObjectColl ectionBase and I want to
serialize and deserialize with the XMLSerializer object. This works great
but my problem is that when the deserialization occurs, it uses the
default
add method to add objects to the collection without adding the keys.

My question is this. Is there any way to use the XMLSerializer object to
deserialize and inform the deserialization process which attribute or
element
should be considered the key and have it call a different add method with
the
key? Or what approach do I have to take?

Thanks
Mark Overstreet

Nov 16 '05 #2

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

Similar topics

11
18699
by: Pavils Jurjans | last post by:
Hello, There's some confusion about the purpose and difference between these handy classes... First, both of them are holding number of key - value pairs, right? Then, I see that there may be some difference in terms of data types allowed for keys and values, perhaps? I read the following in MSDN about "CollectionBase" class and
1
2006
by: igitur | last post by:
Hi all, I have a custom collection derived from System.Collections.Specialized.NameObjectCollectionBase. NameObjectCollectionBase already implements ISerializable, so it should be easy to store in the ViewState, right? I'm, however, unable to do so. I can add the collection object successfully, but with the page reload, it tells me the ViewState is
2
2201
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple properties, ProdID, Description, Quantity and UPC. 3 strings and a long. The LineItemsCollection class inherits from System.Collections.Specialized.NameObjectCollectionBase. It also implements both IEnumerable and IList.
1
1369
by: jamie_m_ | last post by:
I have a custom collection ... clFile that INHERITS from NameObjectCollectionBase the problem is, when I try to create an xmlserializer instance i get an error You must implement a default accessor on brWAP.clFile because it inherits from ICollectio I must be having a thick day because I dont have a clue what the error message means. (I have written a defaut property called ITEM in the clFile class
34
5691
by: Craig Buchanan | last post by:
Which vb.net object is the best match for the vb6 collection class? Specifically, I would like to be able to access the Item property with an index or a key string. I wrote my own class that inherits from the collectionbase and uses an arraylist to hold values, but i'm missing the Item(string) property. I suppose I could iterate thru the collection and look for a string match, but I thought there might be an easier way. Thanks,
1
1571
by: dx | last post by:
Any ideas? I can't find any examples that support this. I'm thinking a solution may be something like inherting arraylist and containing a hashtable. or Inheriting NameObjectCollectionBase and containing an arraylist to use for looping thru in 'order'.
7
1272
by: Michael Kellogg | last post by:
I created a custom collection based on System.Collections.Specialized.NameObjectCollectionBase. I also implemented two version of the "Item" property and coded them both as Default properties. Now, when I look at the data, everything looks good; the underlying objects in there, and the Item property returns the same even if I just access like this: Label(i), so that is cool. However, I tried to do a For...Each on the object just now...
4
5886
by: Stuart | last post by:
I hope someone can shed some light on an error I've been experiencing for sometime now, but can no longer continue to ignore :-( I've created a custom entity class which implements IEditableObject. I have then created a custom collection for this custom entity which naturally inherits CollectionBase and implements IBindingList. When I bind my custom collection to a DataGridView and started editing, it works correctly only up to the...
7
5504
by: Dale | last post by:
I have a design question. I am creating a custom collection of products. The unique key for the products is productId which is an integer. By default, IndexOf(object obj), when obj is an int, would return the value of obj because it returns the index of the item at position obj. Thoughts I had were to let the default method perform the default behavior and then create an overload as IndexOf(int index, ProductSearchCriteria criteria)...
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5662
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.