I am developing a web application in asp.net 2.0. I have not used serialization in the past. can i still use it even if I am not going to pass the object from one machine to another.
is it kind of a good practice to have [Serializable] on top of the methods anyways?
[Serializable]_
public class PayeeData
{
...
}
I don't see that marking classes as serializable hurts anything, but you only need to so mark it if it's going to be serialized. Often this is only done when you use the session state server:
<sessionState mode="StateServer" etc
I don't mark them as serializable unless I get an error that an object isn't serializable
hello
sahajMarg:
is it kind of a good practice to have [Serializable] on top of the methods anyways?
Sure , its recommened to Mark your class as [Serializable], so that you avoid any failures if you decide to use OOP( out of process) session mode( SQlserver OR state server).
also marking your classes as [Serializable] enables you to pass them through webservices Or to make them as Remote Objects.
i recommened also to exclude the calculated public properties from serialization by marking them with XmlIgnore() attribute
<Serializable()> _Public Class CustomerPrivate _IDAs Integer Public Property ID()As Integer Get Return _IDEnd Get Set(ByVal valueAs Integer) _ID = valueEnd Set End Property Private _nameAs String Public Property Name()As String Get Return _nameEnd Get Set(ByVal valueAs String) _name = valueEnd Set End Property Private _dateOfBirthAs DateTimePublic Property DateOfBirth()As DateTimeGet Return _dateOfBirthEnd Get Set(ByVal valueAs DateTime) _dateOfBirth = valueEnd Set End Property' calculated proeprty , no need to serialize it <System.Xml.Serialization.XmlIgnore()> _Public ReadOnly Property Age()As Integer Get Return Now.Subtract(_dateOfBirth).Days / 365End Get End PropertyEnd Class
thanks anas...
0 comments:
Post a Comment