Example #1
0
    public static void TestDynamicInvokeCastingMisc()
    {
        {
            // DynamicInvoke allows "null" for any value type (converts to default(valuetype)).
            Delegate d    = new DFoo5(Foo5);
            Object[] args = { null };
            d.DynamicInvoke(args);
        }

        {
            // DynamicInvoke allows conversion of T to Nullable<T>
            Delegate d    = new DFoo6(Foo6);
            Object[] args = { 7 };
            d.DynamicInvoke(args);
        }

        {
            // DynamicInvoke allows conversion of T to Nullable<T> but T must match exactly.
            Delegate d    = new DFoo6(Foo6);
            Object[] args = { (short)7 };
            Assert.Throws <ArgumentException>(() => d.DynamicInvoke(args));
        }

        {
            // DynamicInvoke allows conversion of T to Nullable<T> but T must match exactly.
            Delegate d    = new DFoo6(Foo6);
            Object[] args = { E4.Seven };
            Assert.Throws <ArgumentException>(() => d.DynamicInvoke(args));
        }

        return;
    }
Example #2
0
        public static void DynamicInvoke_CastingMisc()
        {
            {
                // DynamicInvoke allows "null" for any value type (converts to default(valuetype)).
                Delegate d = new DFoo5(Foo5);
                object[] args = { null };
                d.DynamicInvoke(args);
            }

            {
                // DynamicInvoke allows conversion of T to Nullable<T>
                Delegate d = new DFoo6(Foo6);
                object[] args = { 7 };
                d.DynamicInvoke(args);
            }

            {
                // DynamicInvoke allows conversion of T to Nullable<T> but T must match exactly.
                Delegate d = new DFoo6(Foo6);
                object[] args = { (short)7 };
                Assert.Throws<ArgumentException>(() => d.DynamicInvoke(args));
            }

            {
                // DynamicInvoke allows conversion of T to Nullable<T> but T must match exactly.
                Delegate d = new DFoo6(Foo6);
                object[] args = { E4.Seven };
                Assert.Throws<ArgumentException>(() => d.DynamicInvoke(args));
            }
        }