question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

INotifyPropertyChanged and inheritance

See original GitHub issue

Hi, 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:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
RicoSutercommented, Oct 6, 2020

I’d just write a synthetic test checking that the output in NJS is correct… PR looks good to me.

1reaction
RicoSutercommented, Oct 5, 2020

We’d need to exclude this code in case there’s a base class

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found