Unexepected behavior with base classes
See original GitHub issueCaliburn.Micro 3.1.0
PropertyChanged.Fody 2.1.1
Not calls NotifyOfPropertyChange()
for property HasComplexClassConflict
when Building
changed in this case:
public class BuildingCardViewModelBase : CardViewModelBase
{
public Building Building { get; set; }
}
public class OperatorBuildingCardViewModel : BuildingCardViewModelBase
{
public bool HasComplexClassConflict
=>
Building?.Conflict != null &&
Building.Conflict.Any(x => x.ConflictValueType == ConflictValueType.ComplexClass);
}
Still not calls NotifyOfPropertyChange()
for property HasComplexClassConflict
when Building
changed in this case:
public class BuildingCardViewModelBase : CardViewModelBase
{
public virtual Building Building { get; set; }
}
public class OperatorBuildingCardViewModel : BuildingCardViewModelBase
{
//! Added Building property overriding
public override Building Building { get; set; }
public bool HasComplexClassConflict
=>
Building?.Conflict != null &&
Building.Conflict.Any(x => x.ConflictValueType == ConflictValueType.ComplexClass);
}
Calls NotifyOfPropertyChange()
for property HasComplexClassConflict
when Building
changed only in this case:
public class BuildingCardViewModelBase : CardViewModelBase
{
public virtual Building Building { get; set; }
}
public class OperatorBuildingCardViewModel : BuildingCardViewModelBase
{
//! Notifying manually added
[AlsoNotifyFor(nameof(HasComplexClassConflict)]
public override Building Building { get; set; }
public bool HasComplexClassConflict
=>
Building?.Conflict != null &&
Building.Conflict.Any(x => x.ConflictValueType == ConflictValueType.ComplexClass);
}
I expected it should work in case 1. Great library!
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Teaching Expected and Unexpected Behaviors
Help your students improve their behavior and consider how it affects others by teaching about expected and unexpected behaviors.
Read more >Classes and code throwing errors and strange unexpected ...
And undefined behavior means anything could happen if you do so. You may see errors, see exceptions, see core dumps, see no error...
Read more >Unexpected behavior with abstract test classes · Issue #1222
The issue is when you don't have a child class and you only pass the abstract class in the suite. Agree, we can...
Read more >Teaching Expected & Unexpected Behaviors the Right Way
Behaviors that are unexpected for the situation tend to result in people feeling confused, or sometimes annoyed, nervous, or angry.
Read more >Unexpected behaviour with GetComponent on Inherited ...
I created a derived class PunCharacterNew, inheriting from the base Opsive class PunCharacter for the purpose of overriding one of the base ......
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
@AsValeO in theory it probably could. But it would be enabling a design that will cause you long term pain. You would be much better served long term by just duplicating the Building property in child classes. If u need to treat the base in common code scenarios then you can achieve this using an interface instead of a base class
Case 1 is not possible because the notification for the subclass
OperatorBuildingCardViewModel
has to be done in the base classBuildingCardViewModelBase
which is bad object orientation. A base class should not know about subclasses.I would have thought case 2 would work, but I’m not certain. @SimonCropp can you confirm?