public void TestInterfacedValueTypesAreBoxed()
        {
            var      e1 = new ExampleStruct2();
            IExample e2 = e1;

            e1.Value++;
            Assert.AreEqual(1, e1.Value);
            e1.Value++;
            Assert.AreEqual(0, e2.Value);
        }
Exemple #2
0
    public unsafe static void Main()
    {
        ExampleStruct2 ex   = new ExampleStruct2();
        byte *         addr = (byte *)&ex;

        Console.WriteLine("Size:      {0}", sizeof(ExampleStruct2));
        Console.WriteLine("b1 Offset: {0}", &ex.b1 - addr);
        Console.WriteLine("b2 Offset: {0}", &ex.b2 - addr);
        Console.WriteLine("i3 Offset: {0}", (byte *)&ex.i3 - addr);
        Console.WriteLine("a4 Offset: {0}", ex.a4 - addr);
        Console.WriteLine("d5 Offset: {0}", (byte *)&ex.d5 - addr);
    }
        public void TestCreateAction2d()
        {
            string  n   = nameof(ExampleStruct2.Increment);
            Action2 inc = Accelerator.CreateAction2(typeof(ExampleStruct2).GetMethod(n, new[] { typeof(int) }));

            var unboxed = new ExampleStruct2();

            unboxed.Increment(1);
            Assert.AreEqual(1, unboxed.Value);

            IExample boxed = unboxed;

            inc(boxed, 3);
            Assert.AreEqual(4, boxed.Value);
            inc(boxed, 11);
            Assert.AreEqual(15, boxed.Value);
        }
        public void TestCreateAction1d()
        {
            string  n   = nameof(ExampleStruct2.Increment);
            Action1 inc = Accelerator.CreateAction1(typeof(ExampleStruct2).GetMethod(n, Type.EmptyTypes));

            var unboxed = new ExampleStruct2();

            unboxed.Increment();
            Assert.AreEqual(1, unboxed.Value);

            IExample boxed = unboxed;

            inc(boxed);
            Assert.AreEqual(2, boxed.Value);
            inc(boxed);
            inc(boxed);
            Assert.AreEqual(4, boxed.Value);
        }
Exemple #5
0
        public void TestCreateFunction1d()
        {
            string     n            = nameof(ExampleStruct2.AppendTextAndGet);
            MethodInfo m            = typeof(ExampleStruct2).GetMethod(n, Type.EmptyTypes);
            Func1      appendAndGet = Accelerator.CreateFunction1(m);

            var unboxed = new ExampleStruct2();

            Assert.AreEqual(null, unboxed.Text);
            unboxed.Text = "ABC";
            Assert.AreEqual("ABCtext", unboxed.AppendTextAndGet());
            Assert.AreEqual("ABCtext", unboxed.Text);

            object boxed = unboxed;

            Assert.AreEqual("ABCtexttext", appendAndGet(boxed));
            Assert.AreEqual("ABCtexttext", ((ExampleStruct2)boxed).Text);
        }
Exemple #6
0
        public void TestCreateFunction2b()
        {
            string     n         = nameof(ExampleStruct2.IncrementAndGet);
            MethodInfo m         = typeof(ExampleStruct2).GetMethod(n, new Type[] { typeof(int) });
            Func2      incAndGet = Accelerator.CreateFunction2(m);

            var unboxed = new ExampleStruct2();

            Assert.AreEqual(0, unboxed.Value);
            Assert.AreEqual(1, unboxed.IncrementAndGet(1));
            Assert.AreEqual(1, unboxed.Value);

            object boxed = unboxed;

            Assert.AreEqual(3, (int)incAndGet(boxed, 2));
            Assert.AreEqual(3, ((ExampleStruct2)boxed).Value);
            Assert.AreEqual(6, (int)incAndGet(boxed, 3));
            Assert.AreEqual(6, ((ExampleStruct2)boxed).Value);
        }