I have multiple types with a member of memberName
type User = {
user_id: int
username: string
email: string
} with member this.memberName = "woo"
Then I want to have a function that can take a type argument of any type with that member and return the value of it.
My logic to this was to create a default instance of that type and check that way, but is returning a NullReferenceException
let inline GetMemberName< 'x when 'x: (member memberName: string)> () =
let defaultType = Unchecked.defaultof<'x>
((^x) : (member memberName: string) defaultType)
GetMemberName<User> ()
Thanks