Skip to content

Interact with Compiled Delegates' Syntax Trees Dynamically

License

Notifications You must be signed in to change notification settings

areller/Autopsy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autopsy

This project is currently under development, stay tuned :)

Nuget

Use Autopsy to read the syntax of compiled delegates.

Autopsy.ILSpy

Uses ILSpy to decompile delegates by reading their IL.

IDelegateReader reader = DelegateReader.CreateCachedWithDefaultAssemblyProvider();

SyntaxTree GetSyntaxTree(MyFunc func)
{
    return reader.Read(func);
}

var tree = GetSyntaxTree(x =>
{
    if (x >= 0 && x < 5) return 1;
    else if (x >= 5 && x < 10) return 2;
    return 3;
});
Console.WriteLine(tree.ToString());

Prints

internal int <Main>b__2_0 (int x)
{
        if (x >= 0 && x < 5) {
                return 1;
        }
        if (x >= 5 && x < 10) {
                return 2;
        }
        return 3;
}

See Demo Project

Autopsy.Roslyn

Coming soon

About

Interact with Compiled Delegates' Syntax Trees Dynamically

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published