I'm also interested in the reply to this one (sorry not to have the answer): I need to be able to pass a type (using typeof<>) to a custom attribute.

Thanks,

Kean

By on 3/25/2008 2:57 AM ()

OK - got it. I only saw Robert's response once I posted myself.

Thanks & sorry for the spam.

Kean

By on 3/25/2008 3:00 AM ()

You could try:

1
2
3
4
    [<Test>]
    [<ExpectedException((type ArgumentException))>]
    member x.simple_read_write() = 
        ...//some stuff

As "let t = (type ArgumentException)" is an alternative to "let t = typeof<ArgumentException>".

The double brackets used to be necessary, but not sure if this is still the case and don't have nunit to hand so can't test this easily.

Cheers,
Rob

By on 1/14/2008 3:22 AM ()

... "let t = (type ArgumentException)" is an alternative to "let t = typeof<ArgumentException>".

Why are there two syntaxes for this? Is it a legacy of OCaml cross-compilation, in the same way that List<int> and int list are both allowed, and presumably frustrating for beginning users?

For my two cents, cleaning up things like this should be a priority of the F# team as they ready their product for the "masses". The syntax of F#, once learned, is a strength because of its concision, but learning it is hard enough without two ways of doing the same thing :-)

Cheers!

Sebastian

By on 4/2/2008 9:43 AM ()

Hi Sebastian,

Yes, cleaning up this sort of thing is a priority. In future release of F# "typeof<_>" will be the standard way of doing things, and "(type _)" will be deprecated.

Kind regards

Don

By on 4/2/2008 1:18 PM ()

Thanks Robert, it works as expected and looks better than typeof<> version :)

p.s. parentheses aren't nessesary here:

[<ExpectedException(type ArgumentException )>]

Regards,

Artjom

By on 1/14/2008 3:45 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper