0

In C# we can get all the details of a method using the following code

XmlDocument doc = new XmlDocument();

Type t = doc.GetType();

System.Reflection.MethodInfo[] methods = t.GetMethods();

Here I am not able to get the comments of a method and the exceptions available in the method.

3
  • 5
    You could use Type t = typeof(XmlDocument); and avoid creating an instance. Commented Apr 4, 2011 at 11:07
  • 1
    The XML documentation is not compiled into the type metadata, if that's what you're trying to get. Commented Apr 4, 2011 at 11:09
  • Comments are not available by reflection, they would not be stored in the assembly itself, only in the .pdb file... Commented Apr 4, 2011 at 11:10

4 Answers 4

4

Comments are stripped at compile time and not part of the runtime metadata.

As for exceptions, any exception can be thrown from any method. Whereas exceptions in a sense are part of the interface of a method, they are not declared and are therefore not part of the runtime metadata either.

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there any other way to know the purpose of a method
1

What do you mean by the exceptions available? Unlike Java, in .Net a method does not declare the exceptions that it can throw.

Comments

0

You cannot get a list of Exceptions that the method can throw, and comments are removed by the compiler.

1 Comment

Is there any other way to know the purpose of the method
0

There is no way to get the comments that are declared on a method like this, because they are not part of the assembly. You can't get the exceptions either, because in C# methods don't declare which exceptions the can throw.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.