【发布时间】:2015-04-14 06:17:08
【问题描述】:
var className = typeof(Console);
var methodInfo = className.GetMethod("WriteLine",new [] { typeof(string) });
我得到了 Writeline 方法的 methodInfo 对象,现在如果我们看到该方法的定义,它看起来像这样。
//
// Summary:
// Writes the specified string value, followed by the current line terminator,
// to the standard output stream.
//
// Parameters:
// value:
// The value to write.
//
// Exceptions:
// System.IO.IOException:
// An I/O error occurred.
public static void WriteLine(string value);
我想要的是获取特定方法的 cmets。 ,有什么方法可以使用反射来实现吗?或任何其他可能的方式?
【问题讨论】:
-
该文档不是 MSIL 的一部分,因此您不会从中获得它。
-
没有。你不能这样做,也没有办法使用反射来实现它。
-
我不这么认为。编译器会忽略 cmets,因此它们不会存储为元数据信息……您必须自己解析源代码。
-
构建 xml 文档文件,并解析 xml 文件以获取该成员的文档。它们不是程序集的一部分。
标签: c# reflection metadata methodinfo