Search code examples
typesf#nunitcustom-attributesfscheck

How to pass a Type as an attribute parameter using F# syntax?


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 [].


Solution

  • 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