5

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?

Jon49
  • 4,444
  • 4
  • 36
  • 73

1 Answers1

8

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
Brian Berns
  • 15,499
  • 2
  • 30
  • 40