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;
本文地址:http://com.8s8s.com/it/it45070.htm