f# - 在 F# 中记录受歧视的联合

标签 f#

是否有在 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/

相关文章:

visual-studio - 列表中元组第二个元素的平均值

exception - 异步抛出异常

f# - 如何在 Foq 中设置返回 async<T> 的模拟?

c# - 手动编写解析器的最佳方法是什么?

f# - 使用 fsharp.data.dll 和异步工作流停止 http 下载到磁盘

f# - 如何在集合上使用模式匹配

multithreading - 为什么我的F#异步代码的第二个片段有效,而第一个无效?

f# - 如何使用基础值定义枚举常量

c# - 延续:我可以在 F# 异步工作流或 C# 异步函数中序列化延续吗?