F# nameof for record property
Asked Answered
T

1

6

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?

Tina answered 9/1, 2021 at 21:14 Comment(0)
D
10

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
Drupelet answered 9/1, 2021 at 21:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.