【发布时间】:2009-11-18 04:22:43
【问题描述】:
这是我的对象
[Serializable()]
public class PersistentObject
{
public virtual int ID {
get { return id; }
protected set { id = value;}
}
...
}
当我尝试将其序列化为 xml 时,我收到一个错误 "The Property or indexer PersistentObject.ID cannot be used in this context because the set accessor is inaccessible" 。如果设置器不存在,它可以正常工作。我想将此 ID 保持为序列化,而不需要涉及 ID 上的 [XmlIgnore()] 的 hacktastic 解决方案。如果我可以仅在 setter 上添加 [XmlIgnore()],我会更喜欢,但编译器会抱怨。有人对此有好的解决方案吗?
【问题讨论】:
-
(请注意,当您单击“接受”时,我添加了一个额外的选项)
标签: c# xml-serialization