I extended the class TreeNode to add some properties of my liking. Anyway,
no problems there, I can add my derived TreeNode into TreeNodeCollections and
use the properties etc. However, when I serialize a class containing my new
TreeNode, it doesn't seem to save all the properties back up the inheritance
chain. The class that is getting serialized has one member to be serialized,
a Dictionary<string, List<IOTreeNode>> where IOTreeNode is the TreeNode
derived class. The List generally has 3 to 5 IOTreeNodes in it. The extra
properties of those are fine. The problem is (totally assuming) that the
Nodes collection of the IOTreeNode is a TreeNodeCollection. So I think the
serializer is serializing TreeNodes inside the Nodes collection even though
the collection contains IOTreeNodes. I can't override the Nodes, and I can't
create a derived TreeNodeCollection.
Any pointers/ideas?
Thanks. 3 6648
GreyAlien007 wrote: I extended the class TreeNode to add some properties of my liking. Anyway, no problems there, I can add my derived TreeNode into TreeNodeCollections and use the properties etc. However, when I serialize a class containing my new TreeNode, it doesn't seem to save all the properties back up the inheritance chain. The class that is getting serialized has one member to be serialized, a Dictionary<string, List<IOTreeNode>> where IOTreeNode is the TreeNode derived class. The List generally has 3 to 5 IOTreeNodes in it. The extra properties of those are fine. The problem is (totally assuming) that the Nodes collection of the IOTreeNode is a TreeNodeCollection. So I think the serializer is serializing TreeNodes inside the Nodes collection even though the collection contains IOTreeNodes. I can't override the Nodes, and I can't create a derived TreeNodeCollection.
Did you implement ISerializable on your own TreeNode class? If so, is
the GetObjectData() method called when the data is serialized?
(debugger will let you know, though it's tricky to catch breakpoints
during serialization).
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
I did not implement ISerializable. I'm using VS2005, whose documentation
says to use the OnSerializing, OnSerialized, OnDeserializing, OnDeserialized
attributes as the preferred method to control serialization. I've used them
before, it's pretty straight forward. However, I have no idea what I should
be doing. The problem is, the serialization functions only get called once
for each root node...if they got called for every node in the nodes
collection I could probably do something useful. I've never use
ISerializable interface, does it let me do something extra special?
"Frans Bouma [C# MVP]" wrote: GreyAlien007 wrote:
I extended the class TreeNode to add some properties of my liking. Anyway, no problems there, I can add my derived TreeNode into TreeNodeCollections and use the properties etc. However, when I serialize a class containing my new TreeNode, it doesn't seem to save all the properties back up the inheritance chain. The class that is getting serialized has one member to be serialized, a Dictionary<string, List<IOTreeNode>> where IOTreeNode is the TreeNode derived class. The List generally has 3 to 5 IOTreeNodes in it. The extra properties of those are fine. The problem is (totally assuming) that the Nodes collection of the IOTreeNode is a TreeNodeCollection. So I think the serializer is serializing TreeNodes inside the Nodes collection even though the collection contains IOTreeNodes. I can't override the Nodes, and I can't create a derived TreeNodeCollection.
Did you implement ISerializable on your own TreeNode class? If so, is the GetObjectData() method called when the data is serialized? (debugger will let you know, though it's tricky to catch breakpoints during serialization).
FB
-- ------------------------------------------------------------------------ Lead developer of LLBLGen Pro, the productive O/R mapper for .NET LLBLGen Pro website: http://www.llblgen.com My .NET blog: http://weblogs.asp.net/fbouma Microsoft MVP (C#) ------------------------------------------------------------------------
GreyAlien007 wrote: I did not implement ISerializable. I'm using VS2005, whose documentation says to use the OnSerializing, OnSerialized, OnDeserializing, OnDeserialized attributes as the preferred method to control serialization. I've used them before, it's pretty straight forward. However, I have no idea what I should be doing. The problem is, the serialization functions only get called once for each root node...if they got called for every node in the nodes collection I could probably do something useful. I've never use ISerializable interface, does it let me do something extra special?
TreeNode already implements ISerializable, so you don't have to do
that again in your class. When a binary/soap formatter serializes an
object graph, it will check if the object to serialize implenents
ISerializable. If it does, it calls GetObjectData() on that object to
get the data of the object to serialize. When the object is
deserialized from data, the deserialization constructor (TreeNode
(SerializationInfo, StreamingContext) ) is called, and as TreeNode is
already implementing ISerializable, they've created 2 methods for
inheriters of TreeNode:
Deserialize() and Serialize().
You should override those two methods.
Say I have my own class: which has some bogus membervar _someVar.
[Serializable]
public class MyTreeNode : TreeNode
{
private int _someVar;
public MyTreeNode(string text) : base(text)
{
_someVar=10;
}
public int SomeVar
{
get { return _someVar;}
set { _someVar = value;}
}
}
Now, when I serialize this class I won't get _someVar in the data and
thus when I deserialize the data, I won't get it back.
To get that done, I need to override Serialize() and Deserialize(), and
be sure the base methods are called as well:
[Serializable]
public class MyTreeNode : TreeNode
{
private int _someVar;
public MyTreeNode(string text) : base(text)
{
_someVar=10;
}
public int SomeVar
{
get { return _someVar;}
set { _someVar = value;}
}
protected override void Serialize (SerializationInfo si,
StreamingContext context)
{
// add my membervariable to the data for serialization
si.AddValue("_someVar", _someVar);
// be sure to call the base class method to get the rest
// of the data added as well.
base.Serialize(si, context);
}
protected override void Deserialize (SerializationInfo
si, StreamingContext context)
{
// read the value back
_someVar = si.GetInt32("_someVar");
// deserialize the rest of the data.
base.Deserialize(si, context);
}
}
That's basicly it. You did this and it didnt work?
Frans "Frans Bouma [C# MVP]" wrote:
GreyAlien007 wrote:
I extended the class TreeNode to add some properties of my liking. Anyway, no problems there, I can add my derived TreeNode into TreeNodeCollections and use the properties etc. However, when I serialize a class containing my new TreeNode, it doesn't seem to save all the properties back up the inheritance chain. The class that is getting serialized has one member to be serialized, a Dictionary<string, List<IOTreeNode>> where IOTreeNode is the TreeNode derived class. The List generally has 3 to 5 IOTreeNodes in it. The extra properties of those are fine. The problem is (totally assuming) that the Nodes collection of the IOTreeNode is a TreeNodeCollection. So I think the serializer is serializing TreeNodes inside the Nodes collection even though the collection contains IOTreeNodes. I can't override the Nodes, and I can't create a derived TreeNodeCollection.
Did you implement ISerializable on your own TreeNode class? If so, is the GetObjectData() method called when the data is serialized? (debugger will let you know, though it's tricky to catch breakpoints during serialization).
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: NewToDotNet |
last post by:
I am getting "Object reference not set to an instance of an object. " when I
attempt to open a C# windows service class in design view, although I was
able to initially create the service and open...
|
by: Philip Reed |
last post by:
I'm trying to write a preferences-handling infrastructure that
serializes prefs to XML. Basically I want to read in a common
"default" prefs set, then read in the user's prefs and override the...
|
by: Mark Rae |
last post by:
Hi,
Can anyone please tell me how to convert an object say, a
System.Web.Mail.MailMessage object, to a byte array and then convert the
byte array to a Base64 string?
Any assistance gratefully...
|
by: rawCoder |
last post by:
Hi All,
I need some advanced samples or references for passing custom objects over
the network using sockets.
Without using Remoting what are other options in .NET Framework for this
binary...
|
by: AVL |
last post by:
Hi,
I'm new to .net. I need some info on serialization.
What is serialization? Why do we need it? Why objects need to be serialized
if they need to be stored in session or viewstate?
|
by: Matthew |
last post by:
I have a nice little Sub that saves data in a class "mySettings" to an XML
file.
I call it like so:
Dim mySettings As mySettings = New mySettings
mySettings.value1 = "someText"
mySettings.value2...
|
by: J. Askey |
last post by:
I am implementing a web service and thought it may be a good idea to return a
more complex class (which I have called 'ServiceResponse') in order to wrap
the original return value along with two...
|
by: benkial |
last post by:
Below is a custom exception class that I created to be shared by my C+
+ and
C# code. It works fine till I need to pass the exception object
through Remoting: every time a FtException is raized in...
|
by: anchiang |
last post by:
Hi All,
I have XML:
<RegistryResponse status="Success" xmlns="urn:oasis:names:tc:ebxml-regrep:registry:xsd:2.1">
<AdhocQueryResponse xmlns="urn:oasis:names:tc:ebxml-regrep:query:xsd:2.1">
...
|
by: Jeremy |
last post by:
I've created a serializable class and put attributes around all the
properties that should be serialized. I return the class from a web
service, but my problem is that the wsdl for the web service...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |