extending serialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron Clamage

    #1

    extending serialization

    Hi,

    I'm not sure that if this is the right forum, but any help would be greatly
    appreciated.

    I am porting some java serialization code to c# and I can't figure out the
    correct way to do it. It seems that either I can use default serialization
    or implement ISerializable. Is there any way to do both (e.g. extend the
    default serialization). In other words, I want to be able to implement my
    custom serialization code but call the default serialization code as well.
    In java, I can do this:

    private void writeObject(Obj ectOutputStream out) throws IOException {
    out.defaultWrit eObject();
    //implement my custom code
    }

    It seems there is no .NET equivalent. In particular I have a class that has
    a GraphicsPath member. This class implements ISerializable so that it can
    correctly serialize the path. But, for the other members including
    references to other objects, I would like to use the default serialization.
    Is this possible? Moreover this class derives from a serializable class
    that does not implement ISerializable. Does the derived class have to
    serialize all of the inherited members as well, if it chooses to do custom
    serialization.

    Thanks so much,
    Aaron


  • Aaron Clamage

    #2
    Re: extending serialization

    To add to/refine this question a bit, is it possible to mix and match custom
    and default serialization along an inheritance hierarchy. If a base class
    uses custom serialization can a derived class use default serialization or
    vice-versa? I haven't been able to make either of these work.

    If anyone can help here, please respond...

    Aaron


    "Aaron Clamage" <aclamage@nospa m.cs.umd.edu> wrote in message
    news:#THunUakDH A.3688@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Hi,
    >
    > I'm not sure that if this is the right forum, but any help would be[/color]
    greatly[color=blue]
    > appreciated.
    >
    > I am porting some java serialization code to c# and I can't figure out the
    > correct way to do it. It seems that either I can use default[/color]
    serialization[color=blue]
    > or implement ISerializable. Is there any way to do both (e.g. extend the
    > default serialization). In other words, I want to be able to implement my
    > custom serialization code but call the default serialization code as well.
    > In java, I can do this:
    >
    > private void writeObject(Obj ectOutputStream out) throws IOException {
    > out.defaultWrit eObject();
    > //implement my custom code
    > }
    >
    > It seems there is no .NET equivalent. In particular I have a class that[/color]
    has[color=blue]
    > a GraphicsPath member. This class implements ISerializable so that it can
    > correctly serialize the path. But, for the other members including
    > references to other objects, I would like to use the default[/color]
    serialization.[color=blue]
    > Is this possible? Moreover this class derives from a serializable class
    > that does not implement ISerializable. Does the derived class have to
    > serialize all of the inherited members as well, if it chooses to do custom
    > serialization.
    >
    > Thanks so much,
    > Aaron
    >
    >[/color]


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: extending serialization

      Aaron,
      If you don't have them the following articles covers every thing you wanted
      to know about serialization but were afraid to ask:

      http://msdn.microsoft.com/msdnmag/issues/02/04/net/
      http://msdn.microsoft.com/msdnmag/issues/02/07/net/
      http://msdn.microsoft.com/msdnmag/issues/02/09/net/

      One of the articles discusses how to leverage the FormatterServic es class
      with your own code. (read mix & match ISerializable classes with "default
      serialization" classes) FormatterServic es is the library that the "default
      serialization" code uses to serialization a class that does not implement
      ISerializable.

      Hope this helps
      Jay

      "Aaron Clamage" <aclamage@nospa m.cs.umd.edu> wrote in message
      news:eNdOl%23bk DHA.2232@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > To add to/refine this question a bit, is it possible to mix and match[/color]
      custom[color=blue]
      > and default serialization along an inheritance hierarchy. If a base class
      > uses custom serialization can a derived class use default serialization or
      > vice-versa? I haven't been able to make either of these work.
      >
      > If anyone can help here, please respond...
      >
      > Aaron
      >
      >
      > "Aaron Clamage" <aclamage@nospa m.cs.umd.edu> wrote in message
      > news:#THunUakDH A.3688@TK2MSFTN GP11.phx.gbl...[color=green]
      > > Hi,
      > >
      > > I'm not sure that if this is the right forum, but any help would be[/color]
      > greatly[color=green]
      > > appreciated.
      > >
      > > I am porting some java serialization code to c# and I can't figure out[/color][/color]
      the[color=blue][color=green]
      > > correct way to do it. It seems that either I can use default[/color]
      > serialization[color=green]
      > > or implement ISerializable. Is there any way to do both (e.g. extend[/color][/color]
      the[color=blue][color=green]
      > > default serialization). In other words, I want to be able to implement[/color][/color]
      my[color=blue][color=green]
      > > custom serialization code but call the default serialization code as[/color][/color]
      well.[color=blue][color=green]
      > > In java, I can do this:
      > >
      > > private void writeObject(Obj ectOutputStream out) throws IOException {
      > > out.defaultWrit eObject();
      > > //implement my custom code
      > > }
      > >
      > > It seems there is no .NET equivalent. In particular I have a class that[/color]
      > has[color=green]
      > > a GraphicsPath member. This class implements ISerializable so that it[/color][/color]
      can[color=blue][color=green]
      > > correctly serialize the path. But, for the other members including
      > > references to other objects, I would like to use the default[/color]
      > serialization.[color=green]
      > > Is this possible? Moreover this class derives from a serializable class
      > > that does not implement ISerializable. Does the derived class have to
      > > serialize all of the inherited members as well, if it chooses to do[/color][/color]
      custom[color=blue][color=green]
      > > serialization.
      > >
      > > Thanks so much,
      > > Aaron
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Mike Schilling

        #4
        Re: extending serialization


        "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@ema il.msn.com> wrote in message
        news:%23s4JHGck DHA.1708@TK2MSF TNGP12.phx.gbl. ..[color=blue]
        > Aaron,
        > If you don't have them the following articles covers every thing you[/color]
        wanted[color=blue]
        > to know about serialization but were afraid to ask:
        >
        > http://msdn.microsoft.com/msdnmag/issues/02/04/net/
        > http://msdn.microsoft.com/msdnmag/issues/02/07/net/
        > http://msdn.microsoft.com/msdnmag/issues/02/09/net/
        >[/color]

        They're good articles and I'm grateful to Mr. Richter for writing them, but
        they don't take the place of a precise specification like Java's

        http://java.sun.com/products/jdk/1.2...alTOC.doc.html

        AFAIK, .NET has no equivalent.


        Comment

        Working...