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

In an ISerializable class, how to serialize / deserialize CollectionBase?

Hi, I have used the ISerializable interface before and the code below worked
fine. Until I derived it from CollectionBase. The code will still serialize
and deserialize the properties in this class and properties derived from
this class but will not serialize or deserialize the properties in
CollectionBase. Like InnerList, which is a read only property of
CollectionBase.

How can I serialize and deserialize the InnerList property of
CollectionBase?

Thanks

Mike

Code

public class SerialCollection : CollectionBase, ISerializable {

public SerialCollection () { }

protected SerialCollection ( SerializationInfo info, StreamingContext
context ) {

string exps = "";

// get the set of serializable members for our class and base classes

Type thisType = this.GetType();

MemberInfo[] mi = thisType.GetFields( BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Instance );

// DeSerialize all of the allowed fields and handle any of the removed
fields.

foreach ( MemberInfo member in mi ) {

try {

((FieldInfo)member).SetValue (this, info.GetValue( member.Name,
((FieldInfo)member).FieldType ));

} catch ( Exception e ) {

// resolve upgrade issues here

switch ( member.Name ) {

case "AddEvent":

// Handle the Event properties

continue;

}

exps += String.Format( "\nError during deserialization setting
Member name: {0} : {1}", member.Name, e.Message );

}

}

// this.InnerList = info.GetString("k");

}

void ISerializable.GetObjectData ( SerializationInfo info, StreamingContext
context ) {

// get the set of serializable members for our class and base classes

Type thisType = this.GetType();

MemberInfo[] mi = thisType.GetFields( BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Instance );

foreach ( MemberInfo member in mi ) {

info.AddValue( member.Name, ((FieldInfo)member).GetValue( this ) );

}

}

}
Nov 15 '05 #1
0 2152

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

Similar topics

14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
7
by: Just D. | last post by:
All, What's the easiest way to deserialize class from the class itself? Step by step. We create some class, add all required USINGs, make this class serializable, then add a method like: ...
3
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one...
4
by: Michael Rich | last post by:
Can anyone point me to a collection class that has serialization/deserialization with it - preferably in XML. I know this can't be done with a collection that inherits from CollectionBase, but...
5
by: Ahmad Jalil Qarshi | last post by:
Hi! I have a class named CClassToSerialize that contain some boolean, string and few custom variable types. Now when I create only a single Object and Serialize/Deserialize everything is...
1
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead...
1
by: davebaranas | last post by:
I am able to serialize this but I get a null exception when I try to deserialize it back Even if I don't make any child classes it throws "Object reference not set to an instance of an object."...
3
by: Phill W. | last post by:
OK, I've asked nicely before; now I'm going to throw down the gauntlet to anyone brave enough to take it up. In VB'2005, can anyone write me a class that inherits from System.Data.DataTable, add...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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,...
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.