如何使用C#和[Serialize]创建XML注释 [英] How to create XML comments using C# and [Serialize]

查看:103
本文介绍了如何使用C#和[Serialize]创建XML注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi, I am serializing a class in C# following this example

http://msdn.microsoft.com/en-us/library/2baksw0z(v=vs.110).aspx

Here is my test class


[Serializable]
public class Test
{
   [XmlElement("SomeXmlElementName")]
   public int Something { get; set; }
}



This works well and creates and when the class content is serialized it creates a file with a node named SomeXmlElementName with the right value.

What I would also like is to include a comment in the XML file and I am looking for some .Net attribute I can use to decorate the method to include the comment. The code below does not compile, but it demonstrates the sort of thing I am after

[Serializable]
public class Test
{
   [XmlElement("SomeXmlElementName"), XmlComment("Some comment to include in the XML file when created"]
   public int Something { get; set; }
}


Does something like this exist at all?

Thank you

推荐答案

看看我对你的问题的评论。

如果您想编写任意XML代码,可以查看 XMLWriter教程 [ ^ ]和使用XmlWriter编写XML [ ^ ]以及 XML文档对象模型(DOM) [ ^ ]。

干杯

Andi
See my comment on your question.
If you want to write arbitrary XML code, you might have a look at XMLWriter Tutorial[^] and Writing XML with the XmlWriter[^] as well as XML Document Object Model (DOM)[^].
Cheers
Andi


这篇关于如何使用C#和[Serialize]创建XML注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆