Пример #1
0
    public static void TestDynamicInvokeCastingPrimitiveWiden()
    {
        {
            // For primitives, value-preserving widenings allowed.
            Delegate d    = new DFoo1(Foo1);
            Object[] args = { 7, (short)7 };
            d.DynamicInvoke(args);
        }

        {
            // For primitives, conversion of enum to underlying integral prior to value-preserving widening allowed.
            Delegate d    = new DFoo1(Foo1);
            Object[] args = { 7, E4.Seven };
            d.DynamicInvoke(args);
        }

        {
            // For primitives, conversion of enum to underlying integral prior to value-preserving widening allowed.
            Delegate d    = new DFoo1(Foo1);
            Object[] args = { 7, E2.Seven };
            d.DynamicInvoke(args);
        }

        {
            // For primitives, conversion to enum after value-preserving widening allowed.
            Delegate d    = new DFoo4(Foo4);
            Object[] args = { E4.Seven, 7 };
            d.DynamicInvoke(args);
        }

        {
            // For primitives, conversion to enum after value-preserving widening allowed.
            Delegate d    = new DFoo4(Foo4);
            Object[] args = { E4.Seven, (short)7 };
            d.DynamicInvoke(args);
        }

        {
            // Size-preserving but non-value-preserving conversions NOT allowed.
            Delegate d    = new DFoo1(Foo1);
            Object[] args = { 7, (uint)7 };
            Assert.Throws <ArgumentException>(() => d.DynamicInvoke(args));
        }

        {
            // Size-preserving but non-value-preserving conversions NOT allowed.
            Delegate d    = new DFoo1(Foo1);
            Object[] args = { 7, U4.Seven };
            Assert.Throws <ArgumentException>(() => d.DynamicInvoke(args));
        }

        return;
    }
Пример #2
0
    public static void DynamicInvoke_CastingDefaultValues()
    {
        {
            // Passing Type.Missing without providing default.
            Delegate d = new DFoo1(Foo1);
            Assert.Throws <ArgumentException>(() => d.DynamicInvoke(7, Type.Missing));
        }

        {
            // Passing Type.Missing with default.
            Delegate d = new DFoo1WithDefault(Foo1);
            d.DynamicInvoke(7, Type.Missing);
        }
    }
Пример #3
0
        public static void DynamicInvoke_CastingPrimitiveWiden()
        {
            {
                // For primitives, value-preserving widenings allowed.
                Delegate d = new DFoo1(Foo1);
                object[] args = { 7, (short)7 };
                d.DynamicInvoke(args);
            }

            {
                // For primitives, conversion of enum to underlying integral prior to value-preserving widening allowed.
                Delegate d = new DFoo1(Foo1);
                object[] args = { 7, E4.Seven };
                d.DynamicInvoke(args);
            }

            {
                // For primitives, conversion of enum to underlying integral prior to value-preserving widening allowed.
                Delegate d = new DFoo1(Foo1);
                object[] args = { 7, E2.Seven };
                d.DynamicInvoke(args);
            }

            {
                // For primitives, conversion to enum after value-preserving widening allowed.
                Delegate d = new DFoo4(Foo4);
                object[] args = { E4.Seven, 7 };
                d.DynamicInvoke(args);
            }

            {
                // For primitives, conversion to enum after value-preserving widening allowed.
                Delegate d = new DFoo4(Foo4);
                object[] args = { E4.Seven, (short)7 };
                d.DynamicInvoke(args);
            }

            {
                // Size-preserving but non-value-preserving conversions NOT allowed.
                Delegate d = new DFoo1(Foo1);
                object[] args = { 7, (uint)7 };
                Assert.Throws<ArgumentException>(() => d.DynamicInvoke(args));
            }

            {
                // Size-preserving but non-value-preserving conversions NOT allowed.
                Delegate d = new DFoo1(Foo1);
                object[] args = { 7, U4.Seven };
                Assert.Throws<ArgumentException>(() => d.DynamicInvoke(args));
            }
        }
Пример #4
0
        public static void DynamicInvoke_CastingDefaultValues()
        {
            {
                // Passing Type.Missing without providing default.
                Delegate d = new DFoo1(Foo1);
                Assert.Throws<ArgumentException>(() => d.DynamicInvoke(7, Type.Missing));
            }

            {
                // Passing Type.Missing with default.
                Delegate d = new DFoo1WithDefault(Foo1);
                d.DynamicInvoke(7, Type.Missing);
            }
        }