예제 #1
0
        public static void DynamicInvoke_RefValueTypeParameter(object[] args, object[] expected)
        {
            Delegate d = new RefIntDelegate(RefIntMethod);

            d.DynamicInvoke(args);
            Assert.Equal(expected, args);
        }
예제 #2
0
        public static void DynamicInvoke_TypeDoesntExactlyMatchRefValueType_ThrowsArgumentException()
        {
            Delegate d = new RefIntDelegate(RefIntMethod);

            Assert.Throws <ArgumentException>(null, () => d.DynamicInvoke((uint)7));
            Assert.Throws <ArgumentException>(null, () => d.DynamicInvoke(IntEnum.One));
        }
예제 #3
0
        public static int Static_Void_RefInt(int value)
        {
            var dlg = new RefIntDelegate(Static_Void_RefIntImpl);
            var v   = value;

            dlg(ref v);
            return(v);
        }
예제 #4
0
        public static int Instance_Void_RefInt(int value)
        {
            var inst = new DelegateTypes();
            var dlg  = new RefIntDelegate(inst.Instance_Void_RefIntImpl);
            var v    = value;

            dlg(ref v);
            return(v);
        }
예제 #5
0
        public static int Static_Void_RefInt_Multicast(int value)
        {
            var dlg1 = new RefIntDelegate(Static_Void_RefIntImpl1);
            var dlg2 = new RefIntDelegate(Static_Void_RefIntImpl2);

            dlg1 += dlg2;

            var v = value;

            dlg1(ref v);

            return(v);
        }
예제 #6
0
    public static void Run()
    {
        Console.WriteLine("Testing LINQ Expressions...");

        {
            ParameterExpression pX  = Expression.Parameter(typeof(int).MakeByRefType());
            RefIntDelegate      del =
                Expression.Lambda <RefIntDelegate>(
                    Expression.Call(null, typeof(TestLinqExpressions).GetMethod(nameof(ModifyByRefAndThrow)), pX), pX).Compile();

            int i = 0;
            try
            {
                del(ref i);
            }
            catch (Exception) { }

            if (i != 123)
            {
                throw new Exception();
            }
        }
    }
예제 #7
0
 public static void DynamicInvoke_TypeDoesntExactlyMatchRefValueType_ThrowsArgumentException()
 {
     Delegate d = new RefIntDelegate(RefIntMethod);
     Assert.Throws<ArgumentException>(null, () => d.DynamicInvoke((uint)7));
     Assert.Throws<ArgumentException>(null, () => d.DynamicInvoke(IntEnum.One));
 }
예제 #8
0
 public static void DynamicInvoke_RefValueTypeParameter(object[] args, object[] expected)
 {
     Delegate d = new RefIntDelegate(RefIntMethod);
     d.DynamicInvoke(args);
     Assert.Equal(expected, args);
 }
예제 #9
0
 public void CallRefIntDelegate(RefIntDelegate d, ref int value)
 {
     d(ref value);
 }