There is no magic Decompile()
for a delegate instance, short of deconstructing the IL (perhaps with mono.cecil). If you want an expression tree, you'll have to start with an expression tree, so have Expression<Func<int, bool>>
througout.
As an edge case, you can get basic method delegate information from the delegate's .Method
(the MethodInfo
) and .Target
(the arg0
) - however, for most scenarios involving a lambda or anonymous method this will point at the compiler-generate method on the capture class, so won't really help you much. It is pretty much limited to scenarios like:
Func<string,int> parse = int.Parse;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…