2

How do i get the description from a object member programmaticly?

If i use the built in Object Browser in Visual Studio i can browse a specific object and get a human redable description for every object. For example browsing {} System.Text.RegularExpressions and choosing the "Match(string)" member would give me the following description in the lower right pane of the Object Browser:

public System.Text.RegularExpressions.Match Match(string input) Member of System.Text.RegularExpressions.Regex

Summary:
Searches the specified input string for the first occurrence of the regular expression specified in the System.Text.RegularExpressions.Regex constructor.

Parameters:
input: The string to search for a match.

Returns:
An object that contains information about the match. Exceptions: System.ArgumentNullException: input is null.

How can i get a Console application in C# to output the same information? I have tried with both reflections and enums but have not manage to work it out. I have search in the matter but since I don't know what i should be searching for i have found nothing to point me in the right direction.

Thanks Wylon

Wylon
  • 53
  • 3

1 Answers1

3

You would need the generated XML file for that, and look up your information in that. The comment data does not get embedded into compiled assemblies.

Roy Dictus
  • 32,551
  • 8
  • 60
  • 76
  • You could also use Reflection and check for the Description attribute for UI components. – CodingBarfield Dec 08 '11 at 12:42
  • @Roy: So there is no way i can generate that information manually? Im really only intrested in the first line so i can output which arguments the specific member need. – Wylon Dec 08 '11 at 12:51
  • @CodingBarfield: Do you have any example or link that shows how it can be done? – Wylon Dec 08 '11 at 12:52
  • @Wylon here you go: var t = inputObject.GetType() var descriptions = (DescriptionAttribute[]) type.GetCustomAttributes(typeof(DescriptionAttribute), false); (don't forget to upvote ;) – CodingBarfield Dec 08 '11 at 12:55
  • GetType() only gives the base object, but I got the idea! After adding .GetMethod("Match") it worked! Thanks alot! – Wylon Dec 08 '11 at 13:16
  • Sorry cant seem upvote, im to fresh on the site.. :( The code i ended up using is the following though. var t = inputObject.GetType().GetMethod(""); DescriptionAttribute[] descriptions = (DescriptionAttribute[]) t.GetCustomAttributes(typeof(DescriptionAttribute), false); if (descriptions.Length > 0) { Console.WriteLine (descriptions[0].Description); } else { Console.WriteLine (t.ToString()); } – Wylon Dec 08 '11 at 13:22