Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 974
Vishal Sharma Avatar asked Feb 13 '15 08:02

Vishal Sharma


People also ask

How do you find the class object of associated class using reflection?

8. How to get the class object of associated class using Reflection? Explanation: forName(String className) returns the Class object associated with the class or interface with the given string name.

How do you create an instance of a class using reflection?

We can use newInstance() method on the constructor object to instantiate a new instance of the class. Since we use reflection when we don't have the classes information at compile time, we can assign it to Object and then further use reflection to access it's fields and invoke it's methods.

Does GetType use reflection?

The most basic way to do reflection is to use the GetType() method, but we can also use reflection to get information about methods, constructors, properties, and more.

How do you use reflection?

You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties. If you are using attributes in your code, reflection enables you to access them.


1 Answers

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.

like image 153
Nir Avatar answered Sep 28 '22 02:09

Nir