您将需要实现ISerializable接口,并覆盖以下功能,可以在其中设置在运行时(你可能想从列表或任何其他方式)的属性
public Employee(SerializationInfo info, StreamingContext ctxt)
{
//Get the values from info and assign them to the appropriate properties
EmpId = (int)info.GetValue("EmployeeId", typeof(int));
EmpName = (String)info.GetValue("EmployeeName", typeof(string));
}
//Serialization function.
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
//You can use any custom name for your name-value pair. But make sure you
// read the values with the same name. For ex:- If you write EmpId as "EmployeeId"
// then you should read the same with "EmployeeId"
info.AddValue("EmployeeId", EmpId);
info.AddValue("EmployeeName", EmpName);
}
看一看在CodeProject
你的问题有点不清楚,你可以尝试改述吗? – Kane 2010-03-10 08:34:54
@Lasse V. Karlsen感谢格式化:) – Ravisha 2010-03-10 10:16:31