PropertyChanged: Cannot depend on Inherited member
Maybe I am missing something very basic but I cannot see why the following does not work. Surely inherited members can be part of Fody?
public class StatusVM : BaseVM
{
[DependsOn("Status")] //doesnt work with or without this
public bool IsVisible
{
get { return Status != null; }
}
}
public class BaseVM: INotifyPropertyChanged
{
public bool Status { get; set; }
}
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 25 (10 by maintainers)
sorry this is not going to happen.
I suggest instead of having a base VM with properties you have a shared interface.
if you dont like this i suggest you stop using Fody
It is not a sensible suggestion. changing a base property should not “also trigger” a property on the child class. This is why no one has come across this in the 4 years the project has been running.
It doesnt matter how useful you think it is. You should not be doing it
No i did not say that.
yes it would. for starters why do u have a base class? if it is to “save you code and not have to implement properties in child classes” then you should rethink your strategy. flattening you hierarchy and duplicating some properties will save you much pain in the future. If you need to have a common (castable) base then this is where interfaces can help you. eg if you want to use the
Statusproperty in multiple places then have some interfaceIExposeStatuswith theStatusproperty.There is a reason people regularly say “use composition over inheritance”, it works. and VMs are one of the most common abusers of inheritance.
Again i didnt say this. and “99% of developers”… please
i was not being rude or defensive. PropertyChanged.Fody is an opinionated approach to injecting INPC. if you dont like those opinions it is best you dont use it.
@dellycowboy that is because the implementation of DependsOn is to inject into the set of the property being depended on. it makes no sense to notify on
IsVisibleinsideBaseVM.Status.so sorry but this is simply not possible to support
You’re right, and that’s totally fair.
All I can do is support other community members, and hope someone forks before I do. After reading the comments, I wanted to address what I read. You’re right, no one owes us anything. And certainly not ridicule.
delly was shutdown for using inheritance to clean up his code and create a reusable framework, which isn’t all uncommon. I felt his suggestion could have been handled with more of an open mind, so I wanted to support him. Again, you’re right. No one has to change this and maybe no one will. But maybe my support will change something. It’s worth that maybe.
I understand your guy’s arguments about how the MDIC compiled code doesn’t make sense and would be a bad code smell to see a base class raise a property on a child class. However, I can think of other arguments in support of delly, too. I’m willing to elaborate, if interested.
I’ll close with saying the project does seem like a great project, over all. Well done. I’ve worked with reducing time on implementing INotifyPropertyChanged in different ways, but doing it with Fody is a neat way. I’m only using it on this one client project, and it’s been nice to work with up until this speedbump.
No one owes you anything. This is a free project.
@dellycowboy You do realize your suggestion would produce the following code?
BaseVMraising a PropertyChanged event for IsVisible makes no sense. This suggests to me thatStatusandIsVisibleshould be in the same class, since one depends on the other.If I saw this code I would question why the base object is firing events for it’s children.