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 ?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With