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 ?

Vishal Sharma
  • 2,773
  • 2
  • 24
  • 36
  • The documentation is not part of the MSIL so you won't get it from it. – Samuel Feb 13 '15 at 08:52
  • No. You cannot do that, and there is no way to achieve it using reflection. – Mike Nakis Feb 13 '15 at 08:53
  • 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. – Selman Genç Feb 13 '15 at 08:53
  • also [this one](http://stackoverflow.com/questions/592139/is-it-possible-to-obtain-class-summary-at-runtime) and [this one](http://stackoverflow.com/questions/15602606/programmatically-get-summary-comments-at-runtime) – James Thorpe Feb 13 '15 at 08:53
  • Build the xml documentation file, and parse the xml file to reach the documentation for the member. They are not part of the assembly. – Sriram Sakthivel Feb 13 '15 at 08:54

1 Answers1

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.

Nir
  • 29,306
  • 10
  • 67
  • 103