C#文档注释 [英] C# documentation comments
问题描述
在关于这个帖子我有我的组件设置为CSC.EXE / DOC所以我有包含文档的意见汇编的XML文件。
In relation to this post I have my assembly set up to csc.exe /doc so I have an xml file for the assembly that includes the documentation comments .
所以我有
- MyAssembly.dll程序
- MyAssembly.xml
现在,看着在XML中,有
Now, looking at the xml, it has
<member name="M:MyAssembly.IFoo.SetTimer(System.Int32,System.Double)">
其中的IFoo是和 SetTimer的(INT在大会定义的接口,双)
是该接口的方法。
where IFoo is an interface defined in the assembly and SetTimer(int, double)
is a method in that interface.
我可以去有关XML,但之前解析这个字符串我去这条路线,它有什么我可以使用从MethodInfo的基准去获取文档库从这样的XML注释。有沙塔一提的答案之一,但现在看来似乎是所有关于MSDN样式文档生成和我找不到它可以让我做我想做的任何实例。
I can go about parsing this string in xml but before I go about that route, it there any library that I could use to go from a MethodInfo reference to getting the documentation comments from such xml. There was a mention of sandcastle in one of the answers but it seems like it's all about MSDN-style documentation generator and I couldn't find any examples that would let me do what I'm trying to do.
感谢
推荐答案
注释不会被编译成汇编,这意味着你不能访问数据的这种方式。尝试使用属性来定义额外的元数据:
Comments are not compiled into the assembly, which means you can't access data this way. Try using attributes to define additional metadata:
public class CommentAttribute : Attribute
{
public CommentAttribute(string comment)
{
this.Comment = comment;
}
public string Comment { get; internal set; }
}
public static string GetComments(this ICustomAttributeProvider provider)
{
var commentAttribute = provider.GetCustomAttributes(typeof(CommentAttribute), true)
.Cast<CommentAttribute>()
.FirstOrDefault();
return (commentAttribute == null ? null : commentAttribute.Comment);
}
这样,你可以在 MethodInfo的实例传递
和简单的调用就可以了 GetComments()
。
That way you can pass in an instance of MethodInfo
and simply call GetComments()
on it.
在你的类型,你再添加:
On your type, you then add:
[Comment("This is metadata compiled in the assembly for this type")]
public class Foo { }
这篇关于C#文档注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!