Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Commenting on partial classes/methods

Tags:

Is there a standard way that the tools used to generate the API documents handle having XML Style comments on partial classes? Basically, how should one comment a partial class/method so that the resulting help documents aren't mangled? This question could vary depending on the tool used, in which case, I guess the two tools that are the most important are:

  • Visual Studio's built in method to create XML documentation
  • Microsoft's Sandcastle

I don't want my XML documentation to come out funky is all

/// <summary>Some Foo class</summary>
public partial class Foo { ... }

/// <summary>Some Foo class that implements some interface.</summary>
public partial class Foo : ISomeInterface { ... }
like image 280
myermian Avatar asked May 12 '11 21:05

myermian


People also ask

What is the advantage of using XML comments?

XML comments help speed development by providing IntelliSense on custom methods and other code constructs. XML comments encourage code reuse by providing a path to generate API style reference documentation from your source code.

Do partial classes have to be in same namespace?

All parts of a partial class should be in the same namespace. Each part of a partial class should be in the same assembly or DLL, in other words you can't create a partial class in source files of a different class library project.

Can partial class have same method name?

Any method, interface, and function declared on a partial class is available for all the other parts. The source file name for each part of the partial class can be different, but each partial class's name must be the same.

What is a restriction for C# partial methods?

There are some rules and restrictions apply to the partial method. The signature of partial method must be same in both partial classes. The partial method must return void. No access modifiers are allowed.


1 Answers

The best practice is to give XML comments to just 1 of the partial definitions. There should be no need to split public comments for 1 class into 2 places. (Of course regular comments still make sense to have in each partial definition.)

The way Visual Studio works is that a comment in one partial definition will override the other. You can confirm this by creating 2 partial definitions of the same class with different XML comments, then create a variable of this type. The intellisense will show only 1 of the XML comments.

This will also be the behavior of any documentation tool that uses the XML comments file generated by Visual Studio, which includes Sandcastle.

like image 144
Keith Avatar answered Oct 12 '22 03:10

Keith