External API
There are three primary interfaces in the API, each with a corresponding implementation:
Interface | Purpose |
---|---|
IDecompiler |
Converts MethodInfo to expression tree. |
IInliner |
Inlines method с alls and property accesses inside a given expression tree. |
IDisassembler |
Converts method body to a list of Instructions. |
There are two approaches to acquire them:
The recommended approach is to register Expressive classes/interfaces in your DI container and then resolve them.
public MyClass(IDecompiler decompiler) { ... }
The simple approach is using methods of the ExpressiveEngine class:
ExpressiveEngine.GetDecompiler();
Note that ExpressiveEngine
methods can be re-routed to DI container on just mocked as well, since they are actually Func<>
fields.
This section describes methods of IDecompiler
interface.
For each interface method there is also an extension method that takes MethodBase
instead of IManagedMethod
.
LambdaExpression Decompile(IManagedMethod method);
Produces a LambdaExpression
that has same number of arguments as your original method if it was static, or one additional first argument of type corresponding to method owner instance type. Essentially, person.get_FullName
becomes (Person this) => this.FirstName + " " + this.LastName
.
Expression Decompile(IManagedMethod method, IList<Expression> arguments);
Produces an expression where all argument references (including first argument this
if method was not static) are substituted. For example, if you had p.FullName
where p
was an external method parameter, you can use it to produce p.FirstName + " " + p.LastName
(though you might consider IInliner
instead).
TODO: put this information into XML doc comments.
TODO