-1

Is there a way programmatically to document methods in a class and have the documentation display just like when a user invokes the dot operator (for example, String.[method]) and can look at what a specific method within a class does? See screen shot. I want to create custom methods for a class in C# and then document that. Then when the user uses that class and then initiates the dot operator (.), they will be presented with the method and the documentation that describes that method

enter image description here

user5199
  • 359
  • 2
  • 15

2 Answers2

2

Yes. Use XML documentation comments.

In Visual C# you can create documentation for your code by including XML elements in special comment fields (indicated by triple slashes) in the source code directly before the code block to which the comments refer, for example:

/// <summary>  
///  This class performs an important function.  
/// </summary>  
public class MyClass{}  

Also see Documenting Your Code With XML Comments

The <summary> tag is very important, and we recommend that you include it because its content is the primary source of type or member information in IntelliSense or an API reference document.

P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
0

You can use inline documentation xml tags for members. Use summary to explain methods or other members. And you can use other tags for detailed documentation.

MSDN Documentation

/// <summary>
/// The main Math class.
/// Contains all methods for performing basic math functions.
/// </summary>
public class Math
{
    // Adds two integers and returns the result
    /// <summary>
    /// Adds two integers and returns the result.
    /// </summary>
    public static int Add(int a, int b)
    {
        // If any parameter is equal to the max value of an integer
        // and the other is greater than zero
        if ((a == int.MaxValue && b > 0) || (b == int.MaxValue && a > 0))
            throw new System.OverflowException();

        return a + b;
    }
}

And you can use some third party tools to create html or chm documentation files using this tags.

One example is Sandcastle documentation

fofik
  • 998
  • 11
  • 17