How to make Databinding type safe and support refactoring

Posted by Ian Ringrose on Stack Overflow See other posts from Stack Overflow or by Ian Ringrose
Published on 2009-08-25T15:44:01Z Indexed on 2010/04/24 22:33 UTC
Read the original article Hit count: 360

Filed under:
|
|
|
|

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:

  1. If the property is removed or renamed, I don’t get a compiler warning.
  2. If a rename the property with a refactoring tool, it is likely the data binding will not be updated.
  3. 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.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about databinding