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.

Unexepected behavior with base classes

See original GitHub issue

Caliburn.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:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
SimonCroppcommented, Jun 5, 2017

@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

1reaction
distantcamcommented, Jun 5, 2017

Case 1 is not possible because the notification for the subclass OperatorBuildingCardViewModel has to be done in the base class BuildingCardViewModelBase 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?

Read more comments on GitHub >

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

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