Operators as operands to ternary conditional operator #7946
Unanswered
ActivistInvestor
asked this question in
Language Ideas
Replies: 1 comment 1 reply
-
This is very unlikely to happen, but you can write a source generator which generates methods for these events and does what you want: [EventMethods]
partial class EventManager
{
public event EventHandler PropertyChanged;
} Your source generator would look for the attribute partial class EventManager
{
public void PropertyChangedAddRemove(EventHandler eventHandler, bool enabled)
{
if(enabled)
this.PropertyChanged += eventHandler;
else
this.PropertyChanged -= eventHandler;
}
} Then elsewhere: bool enabled = true;
var events = PropertyInspector.EventManager;
events.PropertyChangedAddRemove(PropertyInspector_propertyChanged, enabled); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
A constant source of code expansion involves code that adds or removes handlers of events based on a condition.
For example:
Although this is probably out of the realm of possibility, it would be helpful if the ternary conditional operator could accept other operators as operands, so I could instead write:
Beta Was this translation helpful? Give feedback.
All reactions