如何使用F#语法将Type作为属性参数传递?

编程入门 行业动态 更新时间:2024-10-24 13:19:26
本文介绍了如何使用F#语法将Type作为属性参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

FsCheck在其NUnit集成中允许自定义任意:

FsCheck allows a custom Arbitrary in its NUnit integration:

[<Property(Verbose = true, Arbitrary= [typeof<Test.Arithmetic.MyArb>])>] static member MultiplyIdentity (x: int64) = x * 1 = x

此语法无效。我感到有些尴尬,但是显然我以前从未用过:您如何在F#中将类型指定为属性参数? Microsoft 对此一无所知,也没有 Wikibooks项目,我在查找时遇到了一些麻烦( type 无处不在。

This syntax doesn't work. I feel a bit embarrassed to ask, but apparently I never needed this before: how do you specify the type in F# as an attribute parameter? Microsoft says nothing about it, nor does the Wikibooks project and I have some trouble googling this (the word type is omnipresent).

注1:任意参数的类型为键入[] 。

Note 1: the Arbitrary parameter is of type Type [].

推荐答案

我认为您已经接近了,但是 [1; 2; 3] 创建一个 list< int> ,您希望使用 [| 1; 2; 3 |] :

I think you're close, but [1;2;3] creates a list<int>, you want an array literal using [| 1;2;3 |]:

[<Property(Verbose = true, Arbitrary= [| typeof<Test.Arithmetic.MyArb> |])>] static member MultiplyIdentity (x: int64) = x * 1 = x

更多推荐

如何使用F#语法将Type作为属性参数传递?

本文发布于:2023-11-08 07:52:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568790.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   语法   属性   参数   Type

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!