How can I get a method discription

kfy0002 1 Reputation point

We can get the description of a property, such as:

Attribute attribute = memberInfo.GetCustomAttribute(typeof(DescriptionAttribute));
if (attribute != null)
DescriptionAttribute descAttr = attribute as DescriptionAttribute;
string description = descAttr.Description;

But this code is not applicable to MethodInfo, How can I get description(or summary) from a method?

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,955 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Timon Yang-MSFT 9,546 Reputation points

    We can add a specific xml summary as a comment for the method (class, etc.), and then Visual Studio will get it correctly.

            /// <summary>  
            /// This is a test method.  
            /// </summary>  
            public void PrintHW()   
                Console.WriteLine("Hello World!");  


    Programmatically get Summary comments at runtime

    c# getting interface method comments

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. kfy0002 1 Reputation point


    I Will show the summary in my code editor.

    I used "get method summary info" as the keyword to search the relevant web pages on the Internet and found some articles.

    thank you!

    0 comments No comments