public void DynamicBinaryUnsupported() { dynamic x = new AddableNum(23); dynamic y = new AddableNum(42); Assert.Throws <RuntimeBinderException>(() => x * y); }
public void DynamicAddition() { dynamic x = new AddableNum(23); dynamic y = new AddableNum(42); dynamic r = x + y; Assert.Equal(23 + 42, r.Value); }
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); }
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); }
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); }
public void DynamicBinaryUnsupported() { dynamic x = new AddableNum(23); dynamic y = new AddableNum(42); Assert.Throws<RuntimeBinderException>(() => x * y); }
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; }