据我所知,这DebuggerDisplayAttribute不能适用于受歧视工会的个人级别,只能适用于顶层阶级。
相应的文档表明重写该ToString()方法是另一种方法。
以下面的例子为例:
type Target =
| Output of int
| Bot of int
override this.ToString () =
match this with
| Output idx -> $"output #{idx}"
| Bot idx -> $"bot #{idx}"
[<EntryPoint>]
let main _ =
let test = Bot 15
0
Run Code Online (Sandbox Code Playgroud)
当中断返回main并打开手表时test,VS2019 调试器显示Bot 15而不是bot #15.
该文档还表明:
调试器是否评估此隐式 ToString() 调用取决于“工具”/“选项”/“调试”对话框中的用户设置。
我无法弄清楚它指的是什么用户设置。
这在 VS2019 中不可用还是我只是错过了重点?
NuGetFsharpx.Extras包公开了用于正则表达式匹配的活动模式,限定为Fsharpx.Text.Regex.Match.
第一个参数是 BCL 中的 RegexOptions 值。
而不必写:
let someFunc =
| Match RegexOptions.None "...pattern 1..." matches -> ...
| Match RegexOptions.None "...pattern 2..." matches -> ...
| Match RegexOptions.None "...pattern 3..." matches -> ...
...
Run Code Online (Sandbox Code Playgroud)
我希望可以改为(使用修改后的Match'活动模式):
let someFunc =
| Match' "...pattern 1..." matches -> ...
| Match' "...pattern 2..." matches -> ...
| Match' "...pattern 3..." matches -> ...
...
Run Code Online (Sandbox Code Playgroud)
Match'我想出的一种可能的定义是:
let (|Match'|_|) pattern =
function
| Match RegexOptions.None pattern …Run Code Online (Sandbox Code Playgroud)