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\CP hones.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. 2 2235 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 parameter where that parameter is of a type in the
System.Data namespace
// (or a class derived from something in the System.Data namespace).
// Is there any way to prevent this from blowing up?
using System;
|
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 I have to use an array PersonType in the AllPersonalData class. But if I have to implement the "Addition of
PersonalType" (i.e. the step 2), I have to use ArrayList instead of a fixed length array. I know that I can use the ArrayList as an...
|
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 XmlSerializer (as it is) won't allow you to treat an
ICollection (or IEnumerable) object as the root node without using
XmlAttributeOverides or sending in a new root attribute with the
serializer.
|
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 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...
|
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 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...
| |
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 constructor(the one that
has the parametr list as GetObjectData method) i can't using assiment to
List refrence because it is read only
this code could be helpful to undersatnd
|
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 which you can see I'm using
when calling AddValue.
I implemented ISerializable and GeteObjectData.
Here's what I tried:
for (int i = 0; i < this.Count; i++)
info.AddValue("item" + i.ToString(), this, typeof(type) );
|
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 problem is that in my derived classes,
the XML that is automatically generated is lacking the properties of the base
class. For example:
public class MyBaseClass {
public MyBaseClass ( ) { }
private string myVariable;
|
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
{
|
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...
|
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,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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,...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |