I can't seem to apply binary operations to lambda expressions, delegates and method groups.
dynamic MyObject = new MyDynamicClass();
MyObject >>= () => 1 + 1;
The second line gives me error: Operator '>>=' cannot be applied to operands of type 'dynamic' and 'lambda expression'
Why?
Isn't the operator functionality determined by my custom TryBinaryOperation
override?
It's not an issue with MyDynamicClass
, the problem is that you can't have a lambda expression as a dynamic. This however, does appear to work:
dynamic MyObject = new MyDynamicClass();
Func<int> fun = () => 1 + 1;
var result = MyObject >>= fun;
If the TryBinaryOperation
looks like this:
result = ((Func<int>) arg)();
return true;
Then result
will be 2. You can use binder.Operation
to determine which binary operation this is.
dynamic MyObject = new MyDynamicClass();
MyObject >>= new Func<int>(() => 1 + 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With