Does anyone know a trick that would allow me to do something like this (where Function is a Func<bool>:
UnaryNode<bool> compliment = new UnaryNode<bool>()
{ Function = () => !compliment.Right.Value };
The following works in place, but is not as nice.
UnaryNode<bool> compliment = new UnaryNode<bool>();
compliment.Function = () => !compliment.Right.Value;
This is not allowed, as documented in the langauge specification. Section 7.6.10.2:
Nor do I find your second version in any way not “nice.” As for a “trick,” it would be something even more “ugly.” You would need to create a temporary throwaway, and then rely upon lambdas closing over the variable instead of the value. For example, given:
You could then have
Is that more or less “nice” than what you already have?