473,659 Members | 2,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList (Collection) - serialization

There is an interesting article -
http://www.devhood.com/tutorials/tut...=542&printer=t

It shows how to serialize the ArrayList of identical objects. I did it a
year ago and it works fine. The question is if the ArrayList has a set of
different objects of different type, every time different. We know what
types should be involved, but we don't know what objects in what order and
how many are used in the ArrayList. What I really want - to write a
universal class-wrapper for ArrayList to let me serialize and deserialize my
ArrayList with the objects of different types.

What I'm thinking now is:

1) to make all objects involved into the process serializable;
2) serialize all objects in ArrayList one by one, storing their ObjectType
(class name?);
3) create a set of strings containing serialized XML data from all objects;
4) finally serialize and write this serialized set of strings in file, on
the database or wherever.

The back way is almost the same:

1) deserialize this intermediate object (array of strings);
2) create our ArrayList and deserialize all objects one by one using (1);
.... enjoy.

Disadvantages are:

1) speed - it obviously should be slowly;
2) intermediate object and memory consumption;

Advantages are:

1) flexibility - we can use any objects in any combination to create our
ArrayList of objects;
2) flexibility - we can create new objects and add them expanding the
application in future without any risk;
3) flexibility - if we use a standard - built-in deserialization we can skip
any fields if they are not included into serialized string, it can be done
automatically, the values will be used as default;

Any idea else? Is it possible to make it simpler and shorter? Yes, I saw
articles like:

---------------------------------------------------------------------------------------------------
http://www.codeproject.com/csharp/objserial.asp

//Deserialization constructor.
public Employee(Serial izationInfo info, StreamingContex t ctxt)
{
//Get the values from info and assign them to the appropriate properties
EmpId = (int)info.GetVa lue("EmployeeId ", typeof(int));
EmpName = (String)info.Ge tValue("Employe eName", typeof(string)) ;
}

//Serialization function.
public void GetObjectData(S erializationInf o info, StreamingContex t ctxt)
{
//You can use any custom name for your name-value pair. But make sure
you
// read the values with the same name. For ex:- If you write EmpId as
"EmployeeId "
// then you should read the same with "EmployeeId "
info.AddValue(" EmployeeId", EmpId);
info.AddValue(" EmployeeName", EmpName);
}
---------------------------------------------------------------------------------------------------

but all these articles are offering to work with only object type and that
doesn't work for my case at all. That's cool to have a data loader from XML
string in the class constructor, but actually it doesn't help me to
understand what class should be used to deserialize the whole collection
object by object.

Maybe I'm loosing something?

Just D.
Nov 16 '05 #1
0 7290

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

Similar topics

4
7819
by: Christopher Pragash | last post by:
Hello all, Following is the code that I'm using to serialize an arraylist. This code returns an "Unknown" Errror. Any ideas would be of great help. <System.Xml.Serialization.XmlArray(), _ System.Xml.Serialization.XmlArrayItem("User", GetType(User))> Public arrUserList As New ArrayList Private Function InitializeList() As ArrayList
1
4614
by: Jamus Sprinson | last post by:
Before I continue, I'm going to begin by saying I'm not by any means an expert- I've been using .NET with C# for about 4 months now, and basically just learning by example and docs. A game project I work on uses Xml serialization to store game objects for loading. One of the techniques we use is to make an array property and use the set block to perform actions on the values after they're loaded from the xml, as in: public string Ids
2
10047
by: Steven | last post by:
Hello, In my asp.net application, I have the MainForm.aspx.cs (where all the functions are defined) and ClasssificationInfo.cs class. This is the Classification Info class -- using System; using System.Xml.Serialization ; namespace MyAppl
5
8024
by: Brad | last post by:
I would like to serialize an arraylist of objects to xml so I can store the xml in a database column. How would I code the serializing and deserializing? Below is a (overly) simple, incomplete example of what I'd want to accomplish. Thanks Brad Example
18
4728
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class instance. However, the 'indexof' is never calling my overloaded, overrides Equals method. Here is the...
8
3135
by: Esmail Bonakdarian | last post by:
Hello, I am relatively new to C# but like it. I have run into a problem to which I haven't been able to find a solution despite looking. I have an ArrayList that contains several RichTextBoxes (via Add()) I am trying to create a second ArrayList with this information, but I want to make a DEEP copy instead of a shallow one, so that
4
8722
by: eugenet | last post by:
Hello, I am writing a Windows Forms application using .NET Framework 2.0 and Visual Studio 2005. I would like to use Properties.Settings class to persist a collection of custom objects. For that I am creating a setting called Connections of type System.Collections.ArrayList using the Properties designer in VS.
0
3432
by: Steven | last post by:
I'm having trouble using an arraylist of a custom object as an argument in a webservice, everything is in VB.Net. Visual Studio I can pass the custom object as an argument to other webmethods fine, and can return it fine. I can have the webservice return an arraylist of the objects and consume them with no dramas. But whenever I call the method it gives this error, failing on the call, before it actually goes 'into' the function. "The...
0
883
by: yurps | last post by:
how do I get an id into the root element of a serialized arraylist. Hello I got an object JAR which has an Id attribute and then contains a collection of COOKIES. So my Jar object has an arraylist of Cookies. but I want the Cookie elements to show-up underneath the Jar element.
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
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,...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
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
5649
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
4175
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
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.