Esempio n. 1
0
        public void DynamicBinaryUnsupported()
        {
            dynamic x = new AddableNum(23);
            dynamic y = new AddableNum(42);

            Assert.Throws <RuntimeBinderException>(() => x * y);
        }
Esempio n. 2
0
        public void DynamicAddition()
        {
            dynamic x = new AddableNum(23);
            dynamic y = new AddableNum(42);
            dynamic r = x + y;

            Assert.Equal(23 + 42, r.Value);
        }
Esempio n. 3
0
        public void DynamicBinaryUnidirectional()
        {
            dynamic x = new Accumulator(23);
            dynamic y = new AddableNum(42);
            dynamic r = x + y;

            Assert.Equal(23 + 42, r.Value);
            Assert.Throws <RuntimeBinderException>(() => y + x);
        }
Esempio n. 4
0
            public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
            {
                if (binder.Operation == ExpressionType.Add)
                {
                    AddableNum addend = arg as AddableNum;
                    if (addend != null)
                    {
                        result = new Accumulator(Value + addend.Value);
                        return(true);
                    }
                }

                result = null;
                return(false);
            }
Esempio n. 5
0
 public void DynamicBinaryUnidirectional()
 {
     dynamic x = new Accumulator(23);
     dynamic y = new AddableNum(42);
     dynamic r = x + y;
     Assert.Equal(23 + 42, r.Value);
     Assert.Throws<RuntimeBinderException>(() => y + x);
 }
Esempio n. 6
0
 public void DynamicBinaryUnsupported()
 {
     dynamic x = new AddableNum(23);
     dynamic y = new AddableNum(42);
     Assert.Throws<RuntimeBinderException>(() => x * y);
 }
Esempio n. 7
0
 public void DynamicAddition()
 {
     dynamic x = new AddableNum(23);
     dynamic y = new AddableNum(42);
     dynamic r = x + y;
     Assert.Equal(23 + 42, r.Value);
 }
Esempio n. 8
0
            public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
            {
                if (binder.Operation == ExpressionType.Add)
                {
                    AddableNum addend = arg as AddableNum;
                    if (addend != null)
                    {
                        result = new AddableNum(Value + addend.Value);
                        return true;
                    }
                }

                result = null;
                return false;
            }