I’m playing around with quotations and I can’t see an expression pattern for type definitions. Is there really not one, or am I missing something?
<@@ type MyType (name:string) =
member x.Name = name @@>
Gives “Unexpected keyword ‘type’ in quotation literal.”
You can’t. You can only quote code, that is to say, any valid F# expression. Type definitions are not considered as code, but definitions.
What you might want to do is put
ReflectedDefinitionattribute on a type members:If you want to retrieve the AST of members that have
ReflectedDefinitionyou can useExpr.TryGetReflectedDefinitionfunction.E.g, this sample code prints ASTs of all reflected definition members of
MyType: