繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> C#学习笔记之八(Serialization, ActiveX Control)

C#学习笔记之八(Serialization, ActiveX Control)

2007-06-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:Serialization: 1. use attribute // "[serializable]" 2. Formatter // "BinaryFormatter binaryFormatter = new BinaryFormatter();" 3.[Noserialized] //example // if the data can generate based some dat...

Serialization:

1. use attribute

// "[serializable]"

2. Formatter

// "BinaryFormatter binaryFormatter = new BinaryFormatter();"

3.[Noserialized]

//example

// if the data can generate based some data, then no need to serialize them.

// overload the OnSerialization() method to do the caculate work

[Serializable]

class Products : IDeserializationCallback

{

private long statNumber = 1;

private long endNumber;

[NonSerialized] private long[] theProducts;

...

public static void Main()

{

Products p = new Products(1, 10);

p.Serialize();

Products p2 = Products.DeSerialize();

p2.DisplayProducts();

}

public void Serialize()

{

FileStream fileStream =

new FileStream("DoProducts1.out", FileMode.Create);

binaryFormatter.Serialize(fileStream, this);

fileStream.Close();

}

public static Products DeSerialize()

{

FileStream fileStream =

new FileStream("DoProduct1.out", FileMode.Open);

BinaryFormatter binaryFormattter =

new BinaryFormatter();

Products p = (Products) binaryFormatter.DeSerialize(fileStream);

fileStream.Close();

return p;

}

pubic virtual void OnDeserialization(object sender)

{

//Caculate the none serialized data based on the serialized data

}

}

Activex Control:

1. Write in VB or VC

2. Register Activex Control in dos command windows

regsvr32 a.ocx

3. add control to c# project

// Tool->Customize ToolBox->COM Components->select your component

4. call

// label1.Text = axCalculator.Add(ref left, ref right).ToString;

责任编辑:admin
相关文章