Property reassignment prevention

Usually, when I encode a property of classes that can be edited by the user with some kind of binding ... To prevent the execution of GUI logic, I do not allow to assign the same value to the property:

public PMSAccountingYear AccountingYear{ get { return _accountingYear; } set{ if(_accountingYear == value) return; _accountingYear = value; NotifyOtherProperties(); LogChanges(); EmallToTheBoss(); Errr(); BlowBombInTheGarden(); Etc(); } } 

The status check does not look elegant and cannot be detected by any automatic code analysis. Can you offer a better example? Perhaps with one of the attributes?

+4
source share
1 answer

What you do is beautiful. this is the usual way to implement setters for things like INotifyPropertyChanged (also an example on this page).

Since the value has not changed, there is no need to really update the support field, and especially not to notify others of the β€œchanged” value.

+3
source

All Articles