using System;
using System.Runtime.Serialization.Formatters;
using System.IO;
using System.Reflection;
using System.Globalization;
using System.Collections;
using System.Runtime.Serialization;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Runtime.Serialization.Formatters.Soap;
using System.Runtime.Serialization.Formatters.Binary;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
secreteClass obj = new secreteClass();
obj.MyAccNum = 123321456;
obj.Passwd="newPassword";
//// SOAP FORMATTER
SoapFormatter formatter = new SoapFormatter();
Stream objfilestream = new FileStream("c:\\Myserialzed.xml", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(objfilestream, obj);
objfilestream.Close();
//deserialization
Stream objreadstream = new FileStream("c:\\Myserialzed.xml", FileMode.Open, FileAccess.Read, FileShare.Read);
secreteClass objSecrete2 = (secreteClass)formatter.Deserialize(objreadstream);
int Myaccno = objSecrete2.MyAccNum;
Response.Write ("AccNo:{0} " + Myaccno.ToString());
//// BINARY FORMATTER
BinaryFormatter bformatter = new BinaryFormatter();
Stream objbfilestream = new FileStream("c:\\Myserialzed.txt", FileMode.Create, FileAccess.Write, FileShare.None);
bformatter.Serialize(objbfilestream, obj);
objbfilestream.Close();
//deserialization
Stream objBreadstream = new FileStream("c:\\Myserialzed.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
secreteClass objBSecrete2 = (secreteClass)bformatter.Deserialize(objBreadstream);
}
}
[Serializable]
public class secreteClass
{
private int myaccountnumber = 0;
[NonSerialized()]
private string password = "qwerty321";
public int MyAccNum
{
get
{
return myaccountnumber;
}
set
{
myaccountnumber = value;
}
}
public string Passwd
{
get
{
return password;
}
set
{
password = value;
}
}
public secreteClass()
{
}
public void SerializedMethod()
{
}
}
No comments:
Post a Comment