C#中得到的接口方法的意见 [英] c# getting interface method comments
问题描述
说我有
interface IFoo
{
/// <summary>
/// Comments about Bar method goes here.
/// </summary>
void Bar();
}
我使用反射来显示在运行时方法
I'm using reflection to display the methods at runtime
MethodInfo[] mis = typeof(IFoo).GetMethods();
但如果我可以得到包含在&LT的意见,我不知道;总结&gt; &lt;用于方法
; /总结&gt。我认识到,意见只是忽略了我的编译器,但有什么可以做检索意见?现在我有了方法和评价一个单独的文件,但我讨厌冗余,想知道是否有办法做到这一点。
but I was wondering if I can get the comments included in <summary> </summary>
for the methods. I realize that comments are just ignored my the compiler but is there anything that could be done to retrieve comments? Right now I have a seperate file that has the methods and the comments but I hate the redundancy and was wondering if there is any way to do this.
谢谢,
推荐答案
C#编译器CSC.EXE拥有的 / DOC 选项。此XML文件所使用的文档生成器(例如沙堡做这种事情)。
The C# compiler csc.exe has a /doc option that outputs an external XML file having your triple-slash comments. This XML file is used by documentation generators (e.g. Sandcastle does this kind of thing).
这导出XML相同的选项评论可以从Visual Studio。要在Visual Studio开发环境中设置此编译器选项:
That same option to export XML comments is available from Visual Studio. To set this compiler option in the Visual Studio development environment:
- 打开项目的属性页。有关详细信息,请参阅如何:设置项目属性(C#,J#) 。
- 单击生成属性页。
- 修改XML文档文件属性。
您可以使用XML解析器从.NET框架加载此XML文件,访问它的类型,并抓住从身边的相关评论。
You can load up this XML file using an XML parser from the .NET framework, access the Types in it, and grab the related comments from around them.
您说得对C#编译器不会编译注释到元数据。不过微软创造了出口能力,三斜杠注释,这样你就可以得到一个处理它们。
You're right the C# compiler doesn't compile comments into the meta data. However Microsoft created triple-slash comments for export ability, so you can get a handle to them.
作为一个例子,我使XML输出文件选项,并记录了以下方法:
As an example, I enable the XML output file option and documented the following method:
/// <summary>
/// This method parses the given name for
/// capitalization.
/// </summary>
public void ParseStringCase(string name)
{
// behaviour of method...
}
这将产生以下的XML文件中的bin /文件夹....
It produces the following XML in a file in the bin/ folder....
<?xml version="1.0"?>
<doc>
<assembly>
<name>WindowsFormsApplication3</name>
</assembly>
<members>
<member name="M:WindowsFormsApplication3.Form1.ParseStringCase(System.String)">
<summary>
This method parses the given name for
capitalization.
</summary>
</member>
</members>
</doc>
这篇关于C#中得到的接口方法的意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!