Is it possible to add more documentation to existing methods or classes in C#?

Viewed 82

Suppose I am developing a C# library targeting two different platforms (lets say, WinForms and Blazor).

One way to structure the code is to have a "core" set of common files that are partial classes, so that I can add platform-specific code in separate files. So the core might have a Point.cs file:

/// <summary>Class <c>Point</c> models a point in a two-dimensional
/// plane.</summary>
///
public partial class Point 
{
    /// <summary>method <c>draw</c> renders the point.</summary>
    void draw() { ... }
}

My question: What if I wanted to add platform-specific documentation to Point.draw? Or the Point class summary?

Obviously with partial classes I could add new platform specific methods in PointBlazor.cs and PointWinForms.cs, but I know of no way to add documentation to existing methods or the class itself already defined in Point.cs, so that they mention other, platform specific methods. Is that possible in C#?

(eg, imagine the Point class summary might mention only in Blazor that Point is using CSS coordinates or some comment like that.)

1 Answers

What if I wanted to add platform-specific documentation to...

One overlooked tag in the xml documentation is the remarks section which comes after the summary section and can be used handle the one-off(s) situational information.

I suggest that you use that section to point out the differences based on the technology, something like this:

/// <summary>method <c>draw</c> renders the point.</summary>
/// <remarks>
/// If running in Blazor, only use on the client side. No issues on winforms.
/// </remarks>
/// <param name="claims"></param>
Related