Results 1 to 8 of 8

Thread: Serializable class

  1. #1

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Serializable class

    Hello guys and gals,
    I've written classes with serializable attribute before but all of them were just "standalone" classes. By saying "standalone", I mean the class itself does not refer to other custom classes within the same application.
    Now I have a need to write a serializable class that DOES refer to my other custom classes. For example, I have ClassA and ClassB. ClassB will be serializable. One of the properties in classB returns a ClassA object. My question is, in order for classB to be serializable, does ClassA also needs to be serializable?
    Thanks for any inputs.
    Stanav.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Serializable class

    I don't believe so.
    [edit]
    I should explain my thinking. You could create a new non-serializable class with a property that holds a dataset object, which is serializable.
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Serializable class

    For a moment I read that backwards.... W_B is right, the containing class doesn't need to be serializable. Been there, done that. I have a couple t-shirts.

    It's the going the other way that isn't as straight forward.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Serializable class

    If a method returns a type, it doesn't have any impact on serializability. If a type is a member of a different type, then for the containing type to be serialized, all of its members have to support serialization. However, since you said that B returned an A, that sounds like a method returning a type, which has nothing to do with serialization.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Serializable class

    Shaggy, it's a property in ClassB that has ClassA type... I don't know if a property would make any difference than a method (function)...
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Serializable class

    If the property creates a new instance of A and returns it, then you are all set. If the property is just exposing an instance of A that is a member of B, then A has to be serializable. The serialization only affects the data portion of a class.
    My usual boring signature: Nothing

  7. #7
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Serializable class

    Why don't you try it out?

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Serializable class

    Yeah, the property itself isn't serialized, only the data members are.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width