I extended the class TreeNode to add some properties of my liking. Anyway,
no problems there, I can add my derived TreeNode into TreeNodeCollect ions 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<stri ng, 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 TreeNodeCollect ion. 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 TreeNodeCollect ion.
Any pointers/ideas?
Thanks. 3 6677
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 TreeNodeCollect ions 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<stri ng, 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 TreeNodeCollect ion. 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 TreeNodeCollect ion.
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 TreeNodeCollect ions 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<stri ng, 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 TreeNodeCollect ion. 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 TreeNodeCollect ion.
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
(SerializationI nfo, StreamingContex t) ) 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(stri ng 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(stri ng text) : base(text)
{
_someVar=10;
}
public int SomeVar
{
get { return _someVar;}
set { _someVar = value;}
}
protected override void Serialize (SerializationI nfo si,
StreamingContex t context)
{
// add my membervariable to the data for serialization
si.AddValue("_s omeVar", _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 (SerializationI nfo
si, StreamingContex t context)
{
// read the value back
_someVar = si.GetInt32("_s omeVar");
// deserialize the rest of the data.
base.Deserializ e(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 TreeNodeCollect ions 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<stri ng, 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 TreeNodeCollect ion. 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 TreeNodeCollect ion.
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 in design view. This happens
once I restarted Visual Studio adn opened teh solution
Any ideas on how to fix this would be appreciated..
BR...
|
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
defaults as appropriate. I'm trying to do them both using the
SoapFormatter to serialize. But when I try to read in the user's
prefs after reading...
|
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 received.
Best regards,
|
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 serialization.
Thank You
rawCoder
|
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 = "otherText"
xmlSave("C:\folder\file.xml", mySettings)
Here is the sub:
Public Shared Sub xmlSave(ByVal path As String, ByVal config As
|
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 other properties...
bool error;
string lastError;
My whole class looks like this...
using System;
|
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 the Remoting
server side, the client got the following error (see below). Based on
my Google search, I did the best I can to have a constructor...
|
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">
<SQLQueryResult>
<ObjectRef id="urn:uuid:425cb4ea-752c-4276-ae52-db295e8e7dc4" />
<ObjectRef...
|
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 is only
including the Values poperty, and nothing else. Also, when the object gets
serialized out, only the Values property gets serialized. I...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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.
| |