Home All Groups Group Topic Archive Search About

Deserialization constructor

Author
17 Feb 2005 7:52 PM
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
Author
17 Feb 2005 8:29 PM
Sunny
In article <e8NwroSFFHA.***@TK2MSFTNGP15.phx.gbl>,
martin.pare@I_Will_Not_Give_You_My_Address says...
Show quoteHide quote
> 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
Are all your drivers up to date? click for free checkup

Author
17 Feb 2005 8:44 PM
Nicholas Paldino [.NET/C# MVP]
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]
               - mvp@spam.guard.caspershouse.com


Show quoteHide quote
"MP" <martin.pare@I_Will_Not_Give_You_My_Address> wrote in message
news:e8NwroSFFHA.228@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
>

Bookmark and Share