问题
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
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).
Note 1: the Arbitrary
parameter is of type Type []
.
回答1:
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
来源:https://stackoverflow.com/questions/40997380/how-to-pass-a-type-as-an-attribute-parameter-using-f-syntax