What's the merit of Update Controls over PostSharp or Notify Property Weaver

I received this question from Justin 袁 直.

Justin writes

Hello Michael

I've seen many ways of automatically implementing INotifyPropertyChange in Nuget, e.g. PostSharp.NotifyPropertyChanged or Notify Property Weaver. I see these methods also detects dependency relationships and fires propertychanged notification wisely.

Unlike applying an attribute, your method includes extra code in the Model class. So would you be so kind as to tell me what's the merit of your framework over the others?

Thank you very much

I respond

Great question.

The difference between Update Controls and the other libraries you mention is that Update Controls does its dependency analysis at run time. Notify Property Weaver and PostSharp both do this analysis at compile time.

Run-time dependency analysis has the advantage of detecting more cases. For example, if a view model calls a method through an interface, and that method references a property, compile-time analysis wouldn't detect it. Run-time analysis will.

Furthermore, as dependencies change, run-time analysis can adapt. Consider a view model property "if (a) return b else return c". While a is true, the property depends upon b. When it changes to false, the dependency switches to c. Compile-time analysis would lead to a dependency upon b and c at all times.

On the other hand, compile-time analysis has some advantages. It is easier to declare properties using attributes rather than writing code. And run-time analysis incurs some overhead in both time and memory.

I've found that the benefits of run-time analysis outweigh the drawbacks. But please use the technique that makes the most sense for your scenario.

Thank you.