Results 1 to 6 of 6

Thread: Simple question about Serializing classes

  1. #1

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Simple question about Serializing classes

    I'm using serialization to store the data in a collection of objects to disk....

    Will this mean that every method in a class will be saved as well? I really only want to store the state of the properties, not the methods... (or does serialization only save the properties?)

    I have looked thru my books, and can't tell for sure...

    If serialization does save the method functions... how would one go about customizing the serialization to not include the methods...?

    For example:
    VB Code:
    1. Public Class Style
    2.     Private styID As Int32
    3.  
    4.     Public Property StyleID() As Int32
    5.            
    6.  
    7.     Public Sub New(ByVal StyleID As Int32, ByVal StyleName As String, ByVal ManufacturerID As Int32)
    8.        
    9. End Class

    I really only want to save the StyleID, not the code for the constructor... does serialization save the constructor code to disk as well?

  2. #2

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Ah... nevermind, if Java doesn't serialize methods... I doubt .Net would either....

    http://www.dnzone.com/ShowDetail.asp?NewsId=79

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Woldnt be any reason to anyway! Methods wouldnt need to be persisted.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Unhappy

    Yea, that was my gut reaction, but after sittin in front of code for 7 hours, you start seeing things move around your desk, forget to breathe, forget to use = New object.... im losing it... fast

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Your right, serialization only serializes the variables of your class. If they are all value types, .Net will handle this for you with no problems. If the variables are other objects, those other objects need to be able to be serialized, or the serializer will choke.

    The actual properties and methods are not serialized, just the class variables are.

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    LOL. I swear that If statement just grew legs and ran off!
    That is how I feel!

    Thank god it is quittin time.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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