时间:2021-05-20
下面的示例提供对某个已存档类型的基本概述。
示例
// If compiling from the command line, compile with: -doc:YourFileName.xml/// <summary>/// Class level summary documentation goes here./// </summary>/// <remarks>/// Longer comments can be associated with a type or member through/// the remarks tag./// </remarks>public class TestClass : TestInterface{ /// <summary> /// Store for the Name property. /// </summary> private string _name = null; /// <summary> /// The class constructor. /// </summary> public TestClass() { // TODO: Add Constructor Logic here. } /// <summary> /// Name property. /// </summary> /// <value> /// A value tag is used to describe the property value. /// </value> public string Name { get { if (_name == null) { throw new System.Exception("Name is null"); } return _name; } } /// <summary> /// Description for SomeMethod. /// </summary> /// <param name="s"> Parameter description for s goes here.</param> /// <seealso cref="System.String"> /// You can use the cref attribute on any tag to reference a type or member /// and the compiler will check that the reference exists. /// </seealso> public void SomeMethod(string s) { } /// <summary> /// Some other method. /// </summary> /// <returns> /// Return values are described through the returns tag. /// </returns> /// <seealso cref="SomeMethod(string)"> /// Notice the use of the cref attribute to reference a specific method. /// </seealso> public int SomeOtherMethod() { return 0; } public int InterfaceMethod(int n) { return n * n; } /// <summary> /// The entry point for the application. /// </summary> /// <param name="args"> A list of command line arguments.</param> static int Main(System.String[] args) { // TODO: Add code to start application here. return 0; }}/// <summary>/// Documentation that describes the interface goes here./// </summary>/// <remarks>/// Details about the interface go here./// </remarks>interface TestInterface{ /// <summary> /// Documentation that describes the method goes here. /// </summary> /// <param name="n"> /// Parameter n requires an integer argument. /// </param> /// <returns> /// The method returns an integer. /// </returns> int InterfaceMethod(int n);}该示例生成一个包含以下内容的 .xml 文件。
<?xml version="1.0"?><doc> <assembly> <name>xmlsample</name> </assembly> <members> <member name="T:TestClass"> <summary> Class level summary documentation goes here. </summary> <remarks> Longer comments can be associated with a type or member through the remarks tag. </remarks> </member> <member name="F:TestClass._name"> <summary> Store for the Name property. </summary> </member> <member name="M:TestClass.#ctor"> <summary> The class constructor. </summary> </member> <member name="P:TestClass.Name"> <summary> Name property. </summary> <value> A value tag is used to describe the property value. </value> </member> <member name="M:TestClass.SomeMethod(System.String)"> <summary> Description for SomeMethod. </summary> <param name="s"> Parameter description for s goes here.</param> <seealso cref="T:System.String"> You can use the cref attribute on any tag to reference a type or member and the compiler will check that the reference exists. </seealso> </member> <member name="M:TestClass.SomeOtherMethod"> <summary> Some other method. </summary> <returns> Return values are described through the returns tag. </returns> <seealso cref="M:TestClass.SomeMethod(System.String)"> Notice the use of the cref attribute to reference a specific method. </seealso> </member> <member name="M:TestClass.Main(System.String[])"> <summary> The entry point for the application. </summary> <param name="args"> A list of command line arguments.</param> </member> <member name="T:TestInterface"> <summary> Documentation that describes the interface goes here. </summary> <remarks> Details about the interface go here. </remarks> </member> <member name="M:TestInterface.InterfaceMethod(System.Int32)"> <summary> Documentation that describes the method goes here. </summary> <param name="n"> Parameter n requires an integer argument. </param> <returns> The method returns an integer. </returns> </member> </members></doc>编译代码
若要编译该示例,请输入以下命令:
csc XMLsample.cs /doc:XMLsample.xml
此命令创建 XML 文件 XMLsample.xml,可在浏览器中或使用 TYPE 命令查看该文件。
可靠编程
XML 文档以 /// 开头。 创建新项目时,向导会放置一些以 /// 开头的行。 处理这些注释时存在一些限制:
1.文档必须是格式正确的 XML。 如果 XML 格式不正确,则会生成警告,并且文档文件将包含一条注释,指出遇到错误。
2.开发人员可以随意创建自己的标记集。 有一组推荐的标记。 部分建议标记具有特殊含义:
备注
XML 文件不提供有关该类型和成员的完整信息(例如,它不包含任何类型信息)。 若要获取有关类型或成员的完整信息,请将文档文件与对实际类型或成员的反射一起使用。
以上就是c#如何使用 XML 文档功能的详细内容,更多关于c# 使用 XML 文档功能的资料请关注其它相关文章!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了C#实现XML文档的增删改查功能。分享给大家供大家参考,具体如下:1、创建实例XML文件(Books.xml)EverydayItalianGia
本文给大家分享一下C#操作(读取、写入)XML文档的实用方法,这种方法主要是对比较规范的XML文档进行操作,因为它(XML文档)和类对象是严格对应的,否则在反序
文档对象模型xml.dom模块对于Python程序员来说,可能是使用XML文档时功能最强大的工具。不幸的是,XML-SIG提供的文档目前来说还比较少。W3C语言
本文实例讲述了C#通过xpath查找xml指定元素的方法。分享给大家供大家参考。具体如下:orders.xml文档内容如下RemarkableOfficeSup
针对XML文件的操作是C#程序设计中非常常见的功能。本文即以实例展示了C#操作XML文件的几个常见的示例。具体如下:1.返回节点下标publicstaticXm