When I use reflection in ViewDidLoad like this:
foreach (var m in this.GetType().GetMethods()) {
Console.WriteLine (m.Name);
}
without any other code, methods like
Add
set_View
are not there; when I add;
public void PreventOptimizing() {
var x = this.View;
this.View = x;
this.Add (null);
}
to the class and without calling that method, they are there. So I assume the AOT compilation optimizes these methods away as they are not called. I don't know which methods it adds away so I would like the compiler, for my experiment, not to optimize anything away. How can that be done? Or is there another trick preventing automated removal of method?
Edit: so full code, if this isn't clear enough;
- result output will not contain 'Add' and 'set_View';
public class TestController : UIViewController { public override void ViewDidLoad () { base.ViewDidLoad (); foreach (var m in this.GetType().GetMethods()) { Console.WriteLine (m.Name); } } }
- Output does contain Add and set_View;
public class TestController : UIViewController { public void PreventOptimizing() { var x = this.View; this.View = x; this.Add (null); } public override void ViewDidLoad () { base.ViewDidLoad (); foreach (var m in this.GetType().GetMethods()) { Console.WriteLine (m.Name); } } }