2

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.)

Simon Sarris
  • 62,212
  • 13
  • 141
  • 171
  • 2
    from my old C/C++ days, I would just define compile-time variable and have `#ifdef BLAZOR` in core file. After all, partials are resolved somehow at compile time, anyway... Admittedly, a kluge - but nothing better comes to mind – Felix Sep 27 '21 at 18:56

1 Answers1

0

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>
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122