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

Serialization of the class derived from CollectionBase

All,

1. Did anybody write Serialization/Deserialization of some custom class
derived
from the CollectionBase class? The custom class is like a container of many
different simple classes, each one of them is serializable, these methods
have been added and work properly.

As an additional headache this custom class can also include a few object
like collection classes.

What is the better way to get this CollectionClass serialized into XML
string and then restore it from the XML string if required? To serialize all
embedded objects one by one, return string and use this string to serialize
the object at the higher level?

This class implements Add(), Remove(), IndexOf(), Append() and other
methods.

--------------------------------------------------------------------------------------------------------------

2. The second question is:

The class has many private or protected members, almost each one has a
public property. Can we exclude some of these public properties from
serialization? I tried to add
[NonSerialized], but the VS writes the following:

Applications\CPhones.cs(396): Attribute 'NonSerialized' is not valid on this
declaration type. It is valid on 'field' declarations only.

All I tried to do was to add [NonSerialized] before public property.

private Int64 m_iOwnerID = -1;
[NonSerialized]
public int OwnerType
{
get
{
return m_iOwnerType;
}
set
{
m_iOwnerType = value;
}
} // End OwnerType Property

Just D.
Nov 16 '05 #1
2 2218
What is the better way to get this CollectionClass serialized into XML
string and then restore it from the XML string if required?
Create an XML Node of which, each child node will represent an object in
the collection, and then write similar sub-nodes customized for each class.
This will help you deserialize easily. Ofcourse, this is just a blue print,
you might need to build on this.
--------------------------------------------------------------------------------------------------------------

2. The second question is: All I tried to do was to add [NonSerialized] before public property.

private Int64 m_iOwnerID = -1;
[NonSerialized]
public int OwnerType
{
get
{
return m_iOwnerType;
}
set
{
m_iOwnerType = value;
}
} // End OwnerType Property

A property basically is a method (get_OwnerType if you view the IL/Reflect
on the dll, for the accessor, set_ for the mutator). This is why the
compiler throws an exception. The built-in serializer reads all public
properties (because they contain the state of the class) and serializes
them. You can call it a flaw in the design (I will be happy to know why,if
its by design) because this cannot be suppressed because of the above
mentioned error.
The answer is, you need to implement ISerializable, and write your own code
to suppress/ allow access to these properties.

--
http://dotnetjunkies.com/weblog/dotnut
Nov 16 '05 #2
On Fri, 28 Jan 2005 14:49:29 +0530, ra*************@gmail.com wrote:
You can use [XMLIgnore] over the properties also.

Ranjan
--
http://dotnetjunkies.com/weblog/dotnut
Nov 16 '05 #3

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

Similar topics

3
by: Craig Schneider | last post by:
// Can anyone explain the bizarre XML Serialization behavior seen in the following code. // It seems that a collection can not be XML Serialized if it contains an Add() method // with a single...
3
by: Franz | last post by:
Let me describe the flow of my program first. 1. Deserialize data from xml file. 2. Addition of "PersonType" class to the AllPersonalData. 3. Serialize data back to the xml file. My question is...
0
by: rein.petersen | last post by:
Hi All, Some of you may have encountered complications when trying to serialize an object derived from CollectionBase (implementing ICollection or IEnumerable). Specifically, the...
0
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...
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...
2
by: wael radwan | last post by:
how to customize the serialization of a collection that inherited form CollectionBase i.e making the class implementing ISerializable interface because when deserializing using the desrializing...
7
by: Joe | last post by:
I've tracked the performance issue down to a single class. This class derives from CollectionBase and stores a basic value type such as string, int, double, etc... I also store the type itself...
6
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The...
1
by: MindWrapper | last post by:
boost serialization of polymorph classes from DLLs Folks, Let's consider following code -------------------------------- // base.h // abstract base class class IBase {
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...

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.