Documentation generation for types with zero value

The question arose about creating documentation using the C # compiler.

Source:

public class SomeClass { /// <summary> /// Do some work /// </summary> /// <returns cref="Nullable{Boolean}"> /// Some stuff /// </returns> public bool? SomeMethod() { return false; } } 

Compiler-generated XML documentation snippet for SomeMethod method:

 <member name="...." > .... <returns cref="T:System.Nullable`1">SomeStuff</returns> </member> 

Is there any way to make it produce

 <member name="...." > .... <returns cref="T:System.Nullable{System.Boolean}">SomeStuff</returns> </member> 

instead of this.

+4
source share
3 answers

Unfortunately not.

Cannot change the way you create .xml files.

Instead, you have to change what it processes, these files process this syntax, or modify the XML documentation.

The problem here is that Nullable{Boolean} no different from Nullable{T} , because the part between the brackets is not understood as a type, but as a general type parameter. T , Boolean , XYZ , it's all the same.

You will either have to change the tool that reads this (and I donโ€™t know how you will do it), or write your links in different ways:

 /// <returns> /// <see cref="Nullable{T}/> with <c>T</c> being <see cref="Boolean"/>. /// </returns> 
+2
source

How about using

 Nullable<bool> 
+1
source

I use this syntax:

 /// <summary> /// Returns the field value cast into <see cref="int"/>?. /// </summary> /// ... public int? GetNullableInt(string name, int? defaultValue = null) 

This means that the type reference is not 100% accurate, but highlighting the preview of the document documentation is equivalent to what the signature preview looks like (color int , unpainted ? ).

0
source

Source: https://habr.com/ru/post/1485976/


All Articles