Before Serialization

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

    #1

    Before Serialization

    I would like to call a method of an object before the object is serialized.
    I currently have a surrogate that I use for deserilization and was thinking
    I could use one for serialization but that means I have to handle
    GetObjectData for each object which I don't want to do unless there is a way
    to make a generic one to work with any object.

    Any suggestions?

    -Joe


  • Peter Bromberg [C# MVP]

    #2
    RE: Before Serialization

    Joe,
    this "doesn't compute" for me. Why can't you call a method on an instance of
    a class before you serialize it? Please enlighten me.
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "Joe" wrote:
    [color=blue]
    > I would like to call a method of an object before the object is serialized.
    > I currently have a surrogate that I use for deserilization and was thinking
    > I could use one for serialization but that means I have to handle
    > GetObjectData for each object which I don't want to do unless there is a way
    > to make a generic one to work with any object.
    >
    > Any suggestions?
    >
    > -Joe
    >
    >
    >[/color]

    Comment

    • Joe

      #3
      Re: Before Serialization

      Peter,

      I have a class which contains many other objects. Some of these objects (or
      their objects) need some pre-processing before serializing.

      Ideally, I would like to see if an object implements an interface and if so
      call that interfaces methods.

      What I'm doing now is specifically calling the methods on the objects I
      currently know about. I would like something a little more generic.

      A surrogate would work but it requires handling the serialization of every
      object.

      -Joe

      "Peter Bromberg [C# MVP]" <pbromberg@yaho o.nospammin.com > wrote in message
      news:D954D8E1-2274-4694-8F14-49DD00F6DFD6@mi crosoft.com...[color=blue]
      > Joe,
      > this "doesn't compute" for me. Why can't you call a method on an instance
      > of
      > a class before you serialize it? Please enlighten me.
      > Peter
      >
      > --
      > Co-founder, Eggheadcafe.com developer portal:
      > http://www.eggheadcafe.com
      > UnBlog:
      > http://petesbloggerama.blogspot.com
      >
      >
      >
      >
      > "Joe" wrote:
      >[color=green]
      >> I would like to call a method of an object before the object is
      >> serialized.
      >> I currently have a surrogate that I use for deserilization and was
      >> thinking
      >> I could use one for serialization but that means I have to handle
      >> GetObjectData for each object which I don't want to do unless there is a
      >> way
      >> to make a generic one to work with any object.
      >>
      >> Any suggestions?
      >>
      >> -Joe
      >>
      >>
      >>[/color][/color]


      Comment

      • Peter Bromberg [C# MVP]

        #4
        Re: Before Serialization

        Joe:
        For this kind of custom serialization implementation you would most likely
        need to write some sort of pre-processing class, combined with a custom
        serializer or your custom serialization surrogate class.
        Peter

        --
        Co-founder, Eggheadcafe.com developer portal:

        UnBlog:





        "Joe" wrote:
        [color=blue]
        > Peter,
        >
        > I have a class which contains many other objects. Some of these objects (or
        > their objects) need some pre-processing before serializing.
        >
        > Ideally, I would like to see if an object implements an interface and if so
        > call that interfaces methods.
        >
        > What I'm doing now is specifically calling the methods on the objects I
        > currently know about. I would like something a little more generic.
        >
        > A surrogate would work but it requires handling the serialization of every
        > object.
        >
        > -Joe
        >
        > "Peter Bromberg [C# MVP]" <pbromberg@yaho o.nospammin.com > wrote in message
        > news:D954D8E1-2274-4694-8F14-49DD00F6DFD6@mi crosoft.com...[color=green]
        > > Joe,
        > > this "doesn't compute" for me. Why can't you call a method on an instance
        > > of
        > > a class before you serialize it? Please enlighten me.
        > > Peter
        > >
        > > --
        > > Co-founder, Eggheadcafe.com developer portal:
        > > http://www.eggheadcafe.com
        > > UnBlog:
        > > http://petesbloggerama.blogspot.com
        > >
        > >
        > >
        > >
        > > "Joe" wrote:
        > >[color=darkred]
        > >> I would like to call a method of an object before the object is
        > >> serialized.
        > >> I currently have a surrogate that I use for deserilization and was
        > >> thinking
        > >> I could use one for serialization but that means I have to handle
        > >> GetObjectData for each object which I don't want to do unless there is a
        > >> way
        > >> to make a generic one to work with any object.
        > >>
        > >> Any suggestions?
        > >>
        > >> -Joe
        > >>
        > >>
        > >>[/color][/color]
        >
        >
        >[/color]

        Comment

        • Yuan Ren[MSFT]

          #5
          Re: Before Serialization

          Hi Joe,

          Thanks for posting!

          For the current issue, as Peter mentioned, you can write your own
          pre-process class to handle the object which needs to be serialized. In the
          class, the static method can be supplied to do some checking for specific
          work and then to be serialized.

          Thanks for your understanding!

          Yuan Ren [MSFT]
          Microsoft Online Support
          =============== =============== =============== =========
          PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
          updated on February 14, 2006. Please complete a re-registration process
          by entering the secure code mmpng06 when prompted. Once you have
          entered the secure code mmpng06, you will be able to update your profile
          and access the partner newsgroups.
          =============== =============== =============== =========
          When responding to posts, please "Reply to Group" via your newsreader
          so that others may learn and benefit from this issue.
          =============== =============== =============== =========
          This posting is provided "AS IS" with no warranties, and confers no rights.
          =============== =============== =============== =========

          Comment

          Working...