jbevain / mono.reflection

Some useful reflection helpers, including an IL disassembler.
151 stars 51 forks source link

Some instructions for noobs #18

Closed ttodua closed 3 years ago

ttodua commented 6 years ago

It will be good if in readme or somewhere there was more detailed examples for noobs like me, because I can't find a way to read the method body.

maximum i've found an example (after spent much time in google), was this example:

foreach( var x in Mono.Reflection.Disassembler.GetInstructions( MethodBase.GetMethod("method-name-here")   )){
     PrintInstruction(x);   
}

however, I cant understand what is the PrintInstruction at all or how to get method by it's name? (the above code is incorrect)?

1) i just want to output the result (string) in console. 2) I wished also example how to read as string from bytes[] returned by ... MethodBase.GetMethod("method-name-here").GetMethodBody().GetILAsByteArray()

Narvalex commented 3 years ago

The tests project shows a pretty way to print the the IL instructions generated

ttodua commented 3 years ago

@Narvalex thanks!