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作为属性参数传递?
发布评论