PC Review


Reply
Thread Tools Rate Thread

Deserialization constructor

 
 
MP
Guest
Posts: n/a
 
      17th Feb 2005
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


 
Reply With Quote
 
 
 
 
Sunny
Guest
Posts: n/a
 
      17th Feb 2005
In article <(E-Mail Removed)>,
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
 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      17th Feb 2005
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]
- (E-Mail Removed)


"MP" <martin.pare@I_Will_Not_Give_You_My_Address> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# constructor best practice: how much logic to place in a C#constructor Jon Microsoft C# .NET 2 11th Nov 2009 09:18 PM
overloaded constructor, access zero-argument constructor mblatch Microsoft C# .NET 3 8th Apr 2005 09:53 PM
Deserialization constructor MP Microsoft C# .NET 2 17th Feb 2005 08:44 PM
Calling a struct constructor in a class constructor body Karl M Microsoft VC .NET 4 19th Dec 2004 01:21 PM
Calling overloaded constructor with values inside another constructor Tristan Microsoft C# .NET 2 30th Mar 2004 01:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:38 PM.