我有两个类:
namespace Something
{
[Serializable]
public class Spec
{
public string Name { get; set; }
[XmlArray]
public List<Value> Values { get; set; }
}
[Serializable]
public class Value
{
public string Name { get; set; }
public short StartPosition { get; set; }
public short EndPosition { get; set; }
public Value(string name, short startPosition, short endPosition)
{
Name = name;
StartPosition = startPosition;
EndPosition = endPosition;
}
}
}
当我尝试序列化时
var spec = new Spec();
spec.Name = "test";
spec.Values = new List<Value> { new Value("testing", 0, 2) };
var xmls = new XmlSerializer(spec.GetType());
xmls.Serialize(Console.Out, spec);
我遇到了一个错误:
InvalidOperationException
反射类型“Something.Spec”时出现错误。
使用字符串列表没有任何问题。我是否缺少某些属性?