How to get Documentation of method or class using Reflection? [duplicate]
Asked Answered
M

1

7
var className = typeof(Console);
var methodInfo = className.GetMethod("WriteLine",new [] { typeof(string) });

I got a methodInfo object for Writeline method , now if we see a defination of that method , it look like this .

//
        // 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);

what i want is getting the comments for a perticular method. , is there any way i can achieve this using Reflection ? or any other possible way ?

Marvamarve answered 13/2, 2015 at 8:50 Comment(5)
The documentation is not part of the MSIL so you won't get it from it.Espionage
No. You cannot do that, and there is no way to achieve it using reflection.Grosbeak
I don't think so. compiler ignores the comments so they are not stored as metadata information... you will have to parse the source code by yourself.Cowshed
also this one and this oneBekah
Build the xml documentation file, and parse the xml file to reach the documentation for the member. They are not part of the assembly.Sound
D
5

Comments are not compiled by the compiler into the result executable/dll (that's kind of the point of comments) and so they aren't available using reflection because they just don't exist outside of the original source code.

There's nothing you can do about it the data is just not there.

Disdainful answered 13/2, 2015 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.