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

王朝c#·作者佚名  2006-01-09
宽屏版  字体: |||超大  

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;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有