Как узнать исходный код метода из dll через код C#?
Формулировка задачи:
Как узнать исходный код метода из dll через код C#? помогите, пожалуйста!!
Решение задачи: «Как узнать исходный код метода из dll через код C#?»
textual
Листинг программы
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Ast;
using Mono.Cecil;
using Mono.Cecil.Rocks;
...
private static string GetSourceCode(string typeName, string methodName)
{
ModuleDefinition module = ModuleDefinition.ReadModule(@"c:\path\to\asm.dll");
TypeDefinition type = module.Types.Single(t => t.FullName == typeName);
MethodDefinition method = type.Methods.Single(t => t.Name == methodName);
AstBuilder astBuilder = new AstBuilder(new ICSharpCode.Decompiler.DecompilerContext(type.Module) { CurrentType = type });
astBuilder.AddMethod(method);
using (var output = new StringWriter())
{
astBuilder.GenerateCode(new PlainTextOutput(output));
return output.ToString();
}
}