473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Serializable class

Hi

What is a Serializable class compared to a normal class?

Thanks

Regards
Nov 20 '05 #1
2 4396
i think it means you can use the serializer to persist the data
to an xml file

not sure how to do that or even how to get the samples to work

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:OB*************@tk2msftngp13.phx.gbl...
Hi

What is a Serializable class compared to a normal class?

Thanks

Regards

Nov 20 '05 #2
In ASP.NET I've found you cannot store a class in a session or viewstate
variable without first marking it as Serializable.

Example:
<Serializable()>_
Public Class Foo
End Class

In a Windows Form if you mark a class Serializable you can save/load it to
disk with code like this:

' class to persist to disk...
<Serializable()> _
Public Class UserSettings
Private _username As String

Public Property UserName() As String
Get
Return _username.ToLower
End Get
Set(ByVal Value As String)
_username = Value.ToLower
End Set
End Property

End Class

' helper class to save/load form disk...
Imports System
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Public Class UserSettingsDB
Private Sub New()
End Sub

Public Shared Function LoadSettings() As UserSettings

Dim mySettings As New UserSettings

Dim s As String = "c:\myapp.bin"

If File.Exists(s) Then

Dim streamOut As FileStream

Try
Dim formatter As New BinaryFormatter

streamOut = New FileStream(s, FileMode.Open,
FileAccess.Read)

mySettings = CType(formatter.Deserialize(streamOut),
UserSettings)

Catch

Finally
streamOut.Close()
End Try
End If

Return mySettings

End Function

Public Shared Sub SaveSettings(ByVal mySettings As UserSettings)

Dim s As String = "c:\myapp.bin"

Dim formatter As New BinaryFormatter

Dim streamIn As New FileStream(s, FileMode.Create,
FileAccess.Write)

formatter.Serialize(streamIn, mySettings)

streamIn.Close()

End Sub

End Class

Greg
"john m" <jm@haengineers.com> wrote in message
news:eK**************@TK2MSFTNGP12.phx.gbl...
i think it means you can use the serializer to persist the data
to an xml file

not sure how to do that or even how to get the samples to work

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:OB*************@tk2msftngp13.phx.gbl...
Hi

What is a Serializable class compared to a normal class?

Thanks

Regards


Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. ...
2
by: jeffpriz | last post by:
I'm having trouble.. I created a small class that I pass to my Pages, and I want to put that class into Viewstate.. I do: Viewstate.add("thisVar", myClassVariable) and i receive the lovely...
9
by: Developer | last post by:
Hi, How can one tell wsdl.exe/VS.NET web service proxy generatioon to to put on imported classes? For example, i fin your web service you use a class: class Data { }
2
by: Frank Uray | last post by:
Hi again I have a little problem with "serializable" a control ... I am creating AppDomain, Assembly and Instance. All works fine. My "base" class for the instance inherit from: -...
1
by: cpnet | last post by:
I have a DataTable defined in a strongly-typed DataSet: public class MyDataSet: DataSet... { ... public class MyDataTable: DataTable... { ...}
1
by: MrFile | last post by:
My company has developed a backend component which needs to be carried around in session state, therefore it must be marked at the class level. The problem I have with this is that now any...
3
by: Techno_Dex | last post by:
I'm wanting to create a Wrapper (or Extender depending on how you look at it) for a Serializable object that I then want to send over a webservice. Basically I want to create a Serializable Object,...
4
by: mark4asp | last post by:
I need to add an item to this class which I would like to be public IncumbentManager List<int>; (alternatively it may be an arraylist, but I prefer a List<int>) This is the simplifed code...
2
by: shapper | last post by:
Hello, I am using ASP.NET Membership and I know each class that I add to Profile must be Serializable: public class Contacts { public string Address { get; set; } }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.