Home  /  Questions  /  Question



85   96.4
Nov 19, 2010


How to get a Class property description using Reflection?

For example, below is a class property. 
I want to get the description words in a summary. How do I do this?

/// <summary>
/// Passenger Type, the length is limited to 3 chars
/// </summary>
public string PassengerType
{
     set { passengertype = value; }
     get { return passengertype; }
}

Thanks!



70   96.1
Dec 22, 2010
If you want to use reflection to retieve the description of a class, you can use DescriptionAttribute to decorate your class/property
something like,




[Description("Passenger Type, the length is limited to 3 chars")]
public string PassengerType
{
     set { passengertype = value; }
     get { return passengertype; }
}

 
 1 comment
 
Thanks, this way works well. --- Zhang Zhao  Dec 27, 2010

1,128   99.9
Nov 21, 2010
Hi,

AFAIK there is no way, using reflection, to get hold of the Xml summary comments. That kind of information is not stored at all. What tools like NDoc and similar do, is that they let Visual Studio generate the comments in a separate xml file and the parse that file to extract the comments.

HTH,
Robert