473,508 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserialization constructor

MP
Hello,
I am having a bit of a problem with Deserialization. I need to "override"
the special constructor used when
an object is deserialize. In thes constructor I have to execute some code
that is requierd by our framework and then call the
'original' special constructor.

How can I call the original constructor from my deserialization
constructor? I do not want to have to manually
do all the assignents to my class members, I just what to call "something"
that knows what to do.
Can anyone point me in the right direction?
[Serializable]

public class SomeEntity : ISerializable

{
public SomeEntity(SerializationInfo info, StreamingContext context)

{
// I want to have my code here...
// some code.

// Then call the "default" constructor.
// What code do I put in there?

}

int m_code = 0;

string m_description = "";

}
Thank you!
-Martin
Nov 16 '05 #1
2 5285
In article <e8*************@TK2MSFTNGP15.phx.gbl>,
martin.pare@I_Will_Not_Give_You_My_Address says...
Hello,
I am having a bit of a problem with Deserialization. I need to "override"
the special constructor used when
an object is deserialize. In thes constructor I have to execute some code
that is requierd by our framework and then call the
'original' special constructor.

How can I call the original constructor from my deserialization
constructor? I do not want to have to manually
do all the assignents to my class members, I just what to call "something"
that knows what to do.
Can anyone point me in the right direction?
[Serializable]

public class SomeEntity : ISerializable

{
public SomeEntity(SerializationInfo info, StreamingContext context)

{
// I want to have my code here...
// some code.

// Then call the "default" constructor.
// What code do I put in there?

}

int m_code = 0;

string m_description = "";

}
Thank you!
-Martin

If you implement ISerializable, then you promise that you will take care
of the serialization. So, it won't work the way you want it.

Sunny
Nov 16 '05 #2
Martin,

You can always call the base constructor with the base keyword, like
this:

public SomeEntity(SerializationInfo info, StreamingContext context) :
base(info, context)
{
// Do other code here.
}

However, this means that the base class' constructor will be called
before your constructor (which makes sense, since the base object fields
have to be fully initialized before you start making changes to it).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"MP" <martin.pare@I_Will_Not_Give_You_My_Address> wrote in message
news:e8*************@TK2MSFTNGP15.phx.gbl...
Hello,
I am having a bit of a problem with Deserialization. I need to "override"
the special constructor used when
an object is deserialize. In thes constructor I have to execute some code
that is requierd by our framework and then call the
'original' special constructor.

How can I call the original constructor from my deserialization
constructor? I do not want to have to manually
do all the assignents to my class members, I just what to call "something"
that knows what to do.
Can anyone point me in the right direction?
[Serializable]

public class SomeEntity : ISerializable

{
public SomeEntity(SerializationInfo info, StreamingContext context)

{
// I want to have my code here...
// some code.

// Then call the "default" constructor.
// What code do I put in there?

}

int m_code = 0;

string m_description = "";

}
Thank you!
-Martin

Nov 16 '05 #3

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

Similar topics

5
5446
by: Burton Roberts | last post by:
This is also posted in the security newsgroup. Sorry for cross-posting, but I'm desperate. I have a Winforms application in VB.NET with a SQL Server (MSDE) backend. In the root application...
4
3138
by: Mike Sarbu | last post by:
Hello all, I have an XML file like this: <?xml version="1.0" encoding="utf-8"?> <SomeObject xmlns="http://www.abcinc.com/objectdefinition"...
1
1499
by: Hector Martinez | last post by:
I have this error, what it means "An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dl Additional information: Exception has been thrown by the...
3
2447
by: Nadav | last post by:
Hi, I have to read files generated by 3rd party application, these files are in a propriotary format ( not generated using the .NET framework ), I want to implement a custom DeSerializer to read...
2
5073
by: Nadav | last post by:
Hi, Introduction: **************** I am trying to DeSerialize a file that was created by an unmanaged application by the binary formatter, to achieve that I am implementing the following...
2
1269
by: Clark Sann | last post by:
I've added a property to one of my classes and now, when I deserialize it I am getting a version mismatch. How to you add or subtract properties in classes that are being serialized /...
0
1183
by: PeterW | last post by:
I have a class which uses three other classes, two of which are used in arrays. This class is only ever used for incoming messages. All classes inherit from ISerializable and impliment...
6
2067
by: Marcus | last post by:
I have a couple of classes looking like this: ======================================== public class AdminSettingsData { public string adminSettingsPath; public string adminSettingsFile;...
7
16125
by: Andrew | last post by:
Hi, I am using DataContractJsonSerializer to deserialize JSON string in C# objects but I am having a problem. Suppose I have a class: class Item { public ItemId Id { get; set; }
0
7393
jinu1996
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...
1
7058
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
7502
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...
0
5635
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,...
1
5057
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...
0
4715
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...
0
3206
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...
0
1565
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 ...
0
426
bsmnconsultancy
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...

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.