public static void Run() { DynamicMethod dm = Util.Compile("if (b >= 10) return; a=1;b=b+a;", typeof(TestPersist)); TestPersist obj = new TestPersist(); DMCall d = (DMCall)dm.CreateDelegate(typeof(DMCall), obj); for (int i = 0; i < 15; i++) { d(); Console.WriteLine(obj.State.GetValue <float>("b")); } dm = Util.Compile("print(x);x=2;nullobj.ToString();", typeof(TestPersist)); d = (DMCall)dm.CreateDelegate(typeof(DMCall), obj); try { d(); } catch { } try { d(); } catch { } }
public static void Run() { DynamicMethod dm = Util.Compile("if (b >= 10) return; a=1;b=b+a;", typeof(TestPersist)); TestPersist obj = new TestPersist(); DMCall d = (DMCall) dm.CreateDelegate(typeof(DMCall), obj); for (int i = 0; i < 15; i++) { d(); Console.WriteLine(obj.State.GetValue<float>("b")); } dm = Util.Compile("print(x);x=2;nullobj.ToString();", typeof(TestPersist)); d = (DMCall) dm.CreateDelegate(typeof(DMCall), obj); try { d(); } catch { } try { d(); } catch { } }