F# nameof for record property

424 views Asked by At

I'm trying to use the new nameof feature in F# 5.0 preview. It works for values but not for record properties, e.g.:

type MyType { Id: int }
let name = nameof MyType.Id

This results in the error FS0728 Field 'Id' is not static

I tried doing:

let name = nameof<MyType.Id>
let name = nameof(MyType.Id)
let name = nameof Id

And neither fix the error. Is there a special way I'm supposed to do this or was nameof not fully implemented?

1

There are 1 answers

0
Brian Berns On BEST ANSWER

This is a duplicate of F# nameof operator not a first-class function.

The short answer is:

let x = Unchecked.defaultof<MyType>
let name = nameof x.Id

Related Questions in F#