- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 XMLSerializer 与城堡事件记录类一起使用,如下所示:
[ActiveRecord("Model")]
public class DataModel : ActiveRecordBase
{
private IList<Document> documents;
[XmlArray("Documents")]
public virtual IList<Document> Documents
{
get { return documents; }
set
{
documents = value;
}
}
}
但是,XMLSerializer 由于 IList 接口(interface)而遇到了麻烦。(引发异常:无法序列化“System.Collections.Generic.IList`1”类型的成员“DataModel.Documents”....)
我在其他地方读到这是 XMLSerializer 中的限制,建议的解决方法是将其声明为 List<T>
而是接口(interface)。
因此我尝试更改 IList<Document>
至List<Document>
。这会导致 ActiveRecord 引发异常:属性 DataModel.Documents 的类型必须是接口(interface)(IList、ISet、IDictionary 或其通用对应部分)。您不能使用 ArrayList 或 List 作为属性类型。
所以,问题是:如何将 XMLSerializer 与包含 IList 成员的 CaSTLe ActiveRecord 一起使用?
最佳答案
有趣...我能建议的最好方法是在 Documents
上使用 [XmlIgnore]
- ActiveRecord 是否有类似的忽略成员的方法?你可以这样做:
[XmlIgnore]
public virtual IList<Document> Documents
{
get { return documents; }
set
{
documents = value;
}
}
[Tell ActiveRecord to ignore this one...]
[XmlArray("Documents"), XmlArrayItem("Document")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public Document[] DocumentsSerialization {
get {
if(Documents==null) return null;
return Documents.ToArray(); // LINQ; or do the long way
}
set {
if(value == null) { Documents = null;}
else { Documents = new List<Document>(value); }
}
}
关于.net - 如何将 XMLSerializer 与包含 IList<T> 成员的 CaSTLe ActiveRecord 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/753099/
在我的 Visual Studio 2010 项目中,我使用以下 Post-Build 事件命令行使用 sgen 创建 XmlSerializers.dll。 构建后事件: "$(ProgramFil
我用 XMLSerializer 类做了一些事情。像大多数初学者一样,我在应用程序启动时遇到性能问题。我阅读了很多博客、文章,最后使用了 SGEN 工具。现在性能看起来还不错,但我还有一些不清楚的地方
过去 2 天我一直被这个问题困扰,但仍然没有解决,我正在寻求帮助。 我的 Listbox根据在 Combobox 中选择的项目,获取添加到其中的生成项目.当我点击按钮时 Create出现一个带有 We
我正在尝试解决如何生成一些 Xml,它使用 XmlSerializer 的一组类中的前缀不仅仅是微不足道的使用。我还希望能够读取相同的 Xml(这相当简单,但随着我使用更复杂的属性似乎消失了。 具体用
XmlSerializer 很难(= 不)反序列化包含表情符号字符的内容,例如 ��。我读过这样的字符在 XML 标准中实际上是非法的;但是,如果我想忠实地表示包含表情符号的聊天对话,则需要它们。如何
我将 XmlSerializer 用于 WCF 服务(就我的服务而言,这是有原因的)。但是最近我遇到了这个问题:我找不到一种简单的方法来使引用类型属性成为必需的,即使其在 XSD 中的定义如下所示:
假设您有两个类,一个继承另一个类,并且子类需要使用 XmlSerializer 进行序列化/反序列化。但是,父级包含一个不可序列化的成员,例如字典。 public class Parent {
我正在尝试使用 XmlSerializer 解析具有如下所示元素的 XML。 amount 元素下有相当多的货币类型,我想将它们反序列化为一个对象集合,这些对象具有保存货币类型的字符串属性和保存金额的
我正在用 Javascript 生成 KML 文档,并尝试使用 XMLSerializer生成 XML 文件,但它生成所有小写标签,即使我在 DOM 中以大写形式创建标签。 是 DOM 破坏了大小写还
我有一小段代码可以将 XML 解析为 JSON。它工作得很好,直到我引入 XMLSerializer 来获取 JSON。 public static String convertXMLFileToSt
假设您有两个类,一个继承另一个,子类需要使用 XmlSerializer 进行序列化/反序列化。但是,父级包含一个不可序列化的成员,比如字典。 public class Parent { pu
我正在尝试使用 XmlSerializer 解析具有如下所示元素的 XML。 amount 元素下有相当多的货币类型,我想将它们反序列化为一个对象集合,这些对象具有保存货币类型的字符串属性和保存金额的
我正在尝试将继承属性的所有成员序列化 (XmlSerializer) 作为特性。 两个类: public class Tree { public Point Location { get; s
我在使用 XmlSerializer 时遇到了修剪字符串的问题, 当使用 XmlReader 时。 IgnoreWhitespace 选项显示无效,元素字符串仍包含\n 和空格。 有什么方法可以“即时
我有以下扩展方法来序列化我的类.... public static string SerializeToXml(this object obj) {
我正在尝试反序列化以下 XML(摘录): Waking The Demon Bullet For My Valentine false B
我在使用 .NET 中的 XmlSerializer 时遇到了一些问题。 这里我有一个我刚刚建立的小例子。 (也可用 @ gist https://gist.github.com/2d84be9041
我从 DTD(通过 XSD 和 xsd.exe)为我的 C# 项目创建了类,因此我可以轻松地将它们反序列化为代码中的模型类。 我大致是这样的: XmlReaderSettings readerSett
我使用 XSD.EXE 将 XSD 转换为对象。这很好用,我可以很好地使用 XMLSerializer 反序列化,除了作为数组生成的子元素不会填充。 private SubElements[]
对不起我的英语。我有 XmlSerializer 的奇怪之处。这是我的代码 [Serializable] public class Radio { public bool hasSubWoof
我是一名优秀的程序员,十分优秀!