【问题标题】:How to get Documentation of method or class using Reflection? [duplicate]如何使用反射获取方法或类的文档? [复制]
【发布时间】: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,因此它们不会存储为元数据信息……您必须自己解析源代码。
  • 还有this onethis one
  • 构建 xml 文档文件,并解析 xml 文件以获取该成员的文档。它们不是程序集的一部分。

标签: c# reflection metadata methodinfo


【解决方案1】:

编译器不会将注释编译到结果可执行文件/dll 中(这就是 cmets 的意义所在),因此它们不能使用反射获得,因为它们只是不存在于原始源代码之外。

您无能为力,因为数据不存在。

【讨论】:

    猜你喜欢
    • 2011-03-06
    • 2011-07-25
    • 1970-01-01
    • 1970-01-01
    • 2019-06-10
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    相关资源
    最近更新 更多