public void TestCastedValueTypesAreBoxed() { var e1 = new ExampleStruct1(); var e2 = (ValueType)e1; e1.Value++; Assert.AreEqual(1, e1.Value); Assert.AreEqual(0, ((ExampleStruct1)e2).Value); }
public void TestCreateFunction2d() { string n = nameof(ExampleStruct1.AppendTextAndGet); MethodInfo m = typeof(ExampleStruct1).GetMethod(n, new Type[] { typeof(string) }); Func2 appendAndGet = Accelerator.CreateFunction2(m); var unboxed = new ExampleStruct1(); Assert.AreEqual("ABC", unboxed.AppendTextAndGet("ABC")); Assert.AreEqual("ABC", unboxed.Text); object boxed = unboxed; Assert.AreEqual("ABCXYZ", (string)appendAndGet(boxed, "XYZ")); Assert.AreEqual("ABCXYZ", ((ExampleStruct1)boxed).Text); }
public void TestCreateAction2c() { string n = nameof(ExampleStruct1.Increment); Action2 inc = Accelerator.CreateAction2(typeof(ExampleStruct1).GetMethod(n, new[] { typeof(int) })); var unboxed = new ExampleStruct1(); unboxed.Increment(1); Assert.AreEqual(1, unboxed.Value); object boxed = unboxed; inc(boxed, 3); Assert.AreEqual(4, ((ExampleStruct1)boxed).Value); inc(boxed, 11); Assert.AreEqual(15, ((ExampleStruct1)boxed).Value); }
public void TestCreateAction1c() { string n = nameof(ExampleStruct1.Increment); Action1 inc = Accelerator.CreateAction1(typeof(ExampleStruct1).GetMethod(n, Type.EmptyTypes)); var unboxed = new ExampleStruct1(); unboxed.Increment(); Assert.AreEqual(1, unboxed.Value); object boxed = unboxed; inc(boxed); Assert.AreEqual(2, ((ExampleStruct1)boxed).Value); inc(boxed); inc(boxed); Assert.AreEqual(4, ((ExampleStruct1)boxed).Value); }
public void TestCreateFunction1b() { string n = nameof(ExampleStruct1.IncrementAndGet); MethodInfo m = typeof(ExampleStruct1).GetMethod(n, Type.EmptyTypes); Func1 incAndGet = Accelerator.CreateFunction1(m); var unboxed = new ExampleStruct1(); Assert.AreEqual(0, unboxed.Value); Assert.AreEqual(1, unboxed.IncrementAndGet()); Assert.AreEqual(1, unboxed.Value); object boxed = unboxed; Assert.AreEqual(2, (int)incAndGet(boxed)); Assert.AreEqual(2, ((ExampleStruct1)boxed).Value); Assert.AreEqual(3, (int)incAndGet(boxed)); Assert.AreEqual(4, (int)incAndGet(boxed)); Assert.AreEqual(4, ((ExampleStruct1)boxed).Value); }