Results 1 to 8 of 8

Thread: good / evil [good wins :) - Resolved]

Threaded View

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    good / evil [good wins :) - Resolved]

    Is it possible or even good or bad practice to code a class so that it can serialize itself?

    I have a class that currently only serializes one of its data members (an array). But how about this...

    VB Code:
    1. <Serializable()> Public Class X
    2.     Shared Function LoadNewObject(ByVal path As String) As X
    3.  
    4.         Dim binser As BinaryFormatter = New BinaryFormatter
    5.         Dim input As Stream = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None)
    6.  
    7.         Dim temp As X
    8.         temp = binser.Deserialize(input)
    9.         input.close()
    10.  
    11.         Return temp
    12.  
    13.     End Function
    14.  
    15.     Public Sub SaveSelf(ByVal path As String)
    16.  
    17.         Dim binser As BinaryFormatter = New BinaryFormatter
    18.         Dim output As Stream = New FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.None)
    19.  
    20.         binser.Serialize(output, Me)
    21.  
    22.         output.Close()
    23.  
    24.     End Sub
    25. End Class

    Your thoughts please.
    Last edited by wossname; May 4th, 2004 at 09:06 AM.
    I don't live here any more.

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