是否有在 F# 中记录受歧视联合的“最佳实践”?我一直在使用XML
标签位于 MSDN website ,但除了 <typeparam name = "x"> Desc. </typeparam>
之外,没有提及记录 DU标签。
这些标签对于标准类型和函数很有帮助,但是XML
标签应该用于 DU?
最佳答案
我大多只使用<summary>
类型及其所有成员的标记(并且由于编译器自动添加 <summary>
,这意味着我不必手动编写任何 XML):
/// Represents a thumbnail that will appear on the movie web site
type MovieThumbnail =
/// Use a PNG image at the specified URL
| Image of string
/// Use a default image for the specified genre
| Default of Genre
可能只有我这么认为,但我发现归档所有其他标签的工作量太大,而且不会为您提供更多信息。
如果您使用F# ProjectScaffold ,那么文档工具在XML注释中也支持Markdown,所以你可以这样写:
/// Represents a thumbnail that will appear on the movie web site
///
/// ## Example
/// The following shows simple pattern matching:
///
/// match movieThumb with
/// | Image(url) -> sprintf "<img src='%s' />" url
/// | Default(g) -> defaultImageFor g
///
type MovieThumbnail =
/// Use a PNG image at the specified URL
| Image of string
/// Use a default image for the specified genre
| Default of Genre
目前,这在 Visual Studio 工具提示中显示得不太好,但如果您正在编写一个库并希望为其提供出色的文档,那么这是获得它的好方法。
关于f# - 在 F# 中记录受歧视的联合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32827048/