Introduce a "OnChangedMethod" attribute
See original GitHub issueclass MyClass : INotifyPropertyChanged
{
[OnChangedMethod(nameof(OnMyPropertyChanged))]
int MyProperty { get; set; }
void OnMyPropertyChanged()
{
}
}
Since we have a nameof
operator today, we could decorate the property with a “link” to the on changed method.
This will avoid the problems with renaming, and omit the compiler warnings that OnMyPropertyChanged
is never used. It also will allow direct navigation to the method from the property.
This attribute would be optional, for those who like to use it. To be fully backward compatible, the weaver would only check that, if the attribute is present, the name of the method matches the desired pattern.
#447 could then also give a hint to properly decorate the property.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (8 by maintainers)
Top Results From Across the Web
HTML onchange Event Attribute
The onchange attribute fires the moment when the value of the element is changed. Tip: This event is similar to the oninput event....
Read more >How onchange Event work in JavaScript | Examples
The onchange event is one of the events in JavaScript which is used for making the change in the state and transforming the...
Read more >onchange attribute: what exactly is the context when calling ...
So in the code, I am referring to checkBox.setAttribute("onchange","checkedBoxes()"), and the function is at the bottom. The HTML is really not ...
Read more >HTML DOM onchange Event
The HTML DOM onchange event occurs when the value of an element has been changed. It also works with radio buttons and checkboxes...
Read more >onChange Javascript
Onchange as Event Attribute. When the changes are made on the select element, a custom function “function” is called through the onchange ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It would need a few changes but not that much (basically adding the method info to
PropertyData
).Also, we could allow the user to provide multiple
OnChangedMethod
attributes, to call multiple methods when a property changes.It wasn’t that bad. I made a draft that I will need to rebase in #464.
It enables stuff like that:
https://github.com/Fody/PropertyChanged/blob/aef044d5d7487de3b776e2df8a69284b21ce9192/TestAssemblies/AssemblyToProcess/ClassWithOnChangedCustomized.cs#L10-L12