Inject property call with Mono Cecil


How can I inject this code into the method Test()?

this.DialogResult = DialogResult.OK;

So the method after injecting will look like this:

public void Test()
this.DialogResult = DialogResult.OK;


That will insert the assignment at the top of the Test method, provided that the field DialogResult is declared in the same type declaring Test (otherwise you'll have to browse its hierarchy to retrieve it):

var module = ModuleDefinition.ReadModule ("assembly.dll");
var container = module.GetType ("Container");
var test = container.Methods.First (m =
By : Jb Evain

This video can help you solving your question :)
By: admin