How to make Databinding type safe and support refactoring
- by Ian Ringrose
When I wish to bind a control to a property of my object, I have to provide the name of the property as a string. This is not very good because:
If the property is removed or
renamed, I don’t get a compiler
warning.
If a rename the property
with a refactoring tool, it is
likely the data binding will not be
updated.
I don’t get an error until
runtime if the type of the property
is wrong, e.g. binding an integer to
a date chooser.
Is there a design-paten that gets round this, but still has the ease of use of data-binding?
(This is a problem in WinForm, Asp.net and WPF and most likely lots of other systems)
I have now found "workarounds for nameof() operator in C#: typesafe databinding" that also has a good starting point for a solution.