INotifyPropertyChanged and inheritance
See original GitHub issueHi, I’m having issues with DTO’s generated with Class Style = ‘INPC’ and inheritance.
I found out that every entity has it’s own event:
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
and when I change a property of a base class, the method RaisePropertyChanged
find the event null (not subscribed by anyone), while the subscriber in fact had subscribed the derived class event.
protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
I guess the event should be virtual
or (as for Prism
) included in a base class.
Thanks in advance for any help,
D.
EDIT: As a workaround, I’ve switched to Prism
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
c# - Inheritance with INotifyPropertyChanged
When I change the data property of the objClass1 , the modifiedDateTime property of the ExampleClass2 inherited by the base class BaseObject is ......
Read more >Lesson 04.4: Improving the World – Inheritance and ...
One way to share code is to create a “base” class, and have your other classes “inherit” from that base class. That is...
Read more >INotifyPropertyChanged attributes - .NET Community Toolkit
These attributes are only meant to be used in cases where the target types cannot just inherit from the equivalent types (eg. from ......
Read more >Implementing INotifyPropertyChanged - YouTube
In this video, we discuss some of the implications of implementing INotifyPropertyChanged with inheritance, and review testing classes that ...
Read more >c# - favor composition over inheritance: practical problems
PropertyChanged on all my classes that require an INotifyPropertyChanged implementation. Problem solved, no inheritance required.
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
I’d just write a synthetic test checking that the output in NJS is correct… PR looks good to me.
We’d need to exclude this code in case there’s a base class