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 ReflectedDefinition
attribute on a type members:
type MyType (name : string) =
[<ReflectedDefinition>] member x.Name = name
If you want to retrieve the AST of members that have ReflectedDefinition
you can use Expr.TryGetReflectedDefinition
function.
E.g, this sample code prints ASTs of all reflected definition members of MyType
:
open Microsoft.FSharp.Quotations
open System.Reflection
type MyType (name : string) =
[<ReflectedDefinition>] member x.Name = name
let mis = typeof<MyType>.GetMembers()
for mi in mis do
try
match Expr.TryGetReflectedDefinition(mi :?> MethodBase) with
| Some(e) -> printfn "%A" e
| None -> ()
with _ -> ()
()