With advent of WPF and MVVM Microsoft introduced DependencyProperties
and INotifyPropertyChange
interface to provide a way to implement the “reactive” approach used with those technologies.
Sadly both of these constructs are very verbose, require much boilerplate, are clumsy to use, also are not really that safe since they require much use of “magic strings”.
So here come the question: why didn’t they put these functionalities directly into the language – why didn’t they create new kind of properties created with a simple keyword, providing useful stuff of DependencyProperties
(like events on change and so on…).
What were stopping them?
Dependecy properties are very WPF-specific. As far as I know, even WinRT (which is XAML-based, just like WPF) doesn’t use them. So, you are proposing adding a feature that wouldn’t be at all useful for people who develop ASP.NET applications, Windows services, web services, WinRT applications, etc. That’s points against this feature.
Also, it’s not clear to me how exactly would this work. How would you set the default value of the property? Or PropertyChangedCallback
? What about attached properties? If the feature you’re proposing couldn’t handle all this, it would make it much less useful. If it did, I have no idea how would the syntax look like, but I doubt it would fit well with the rest of C#.
And this feature doesn’t actually add much, it just makes some code slightly more convenient.
This all says to me that such a feature wouldn’t be worth it, considering that it would be relatively complicated change that would be useful only in a relatively small subset of programs and even in those wouldn’t be actually useful that much.
1
I’d guess their reason might be: Having to support that language support even long after WPF is dead.
ViewModels aren’t supposed to contain any logic, so any implementation code pretty much is “write-only”. And with snippet support in Visual Studio writing dependency properties isn’t any harder than writing regular properties: propdp
tab
tab
. Replace the snippet with one using a lambda instead of the magic string (like this one google found for me) and you are good to go.
Language support wouldn’t improve much upon that, would it?