我有一个名为UnitsManager
的班级。在这个类中是一个枚举:
public enum TimeUnit
{
Seconds,
Milliseconds,
Minutes,
Hours,
Days,
Months,
Years
}
此枚举用于另一个名为Process
的类中。它有一个属性:
private TimeUnit cycleTimeUnit = TimeUnit.Seconds;
[XmlAttribute("CycleTimeUnit")]
public TimeUnit CycleTimeUnit
{
get { return this.cycleTimeUnit; }
set { this.cycleTimeUnit = value; }
}
我正在尝试序列化和反序列化Process
类。我在Process
类
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("CycleTime", CycleTime);
info.AddValue("CycleTimeUnit", CycleTimeUnit);
}
我的问题来自反序列化
private Process(SerializationInfo info, StreamingContext context)
{
CycleTime = info.GetDouble("CycleTime");
CycleTimeUnit = info.????("CycleTimeUnit"); // <--- ???
}
如何将其转换为CycleTimeUnit
类型?
答案 0 :(得分:3)
试试这个:
<div id="element1">element1</div>
<div id="element2">element2</div>
<div id="element3">element3</div>