I have been working on using mvp to wire up some winforms in C#. UI development is not exactly my strong suite and I was looking for a refactor proof way to implement INotifyPropertyChanged without having to resort to strings to fire change notifications.
The msdn example http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx and most of the others I have seen strike me as the wrong way to do it least of all with regards to the fact that the strings have to be changed in case you refactor the properties.
All the other options I have seen on stackoverflow using expressions and func, facilities sadly not available in the legacy solution I am supporting so I was wondering if any one has a way to replicate the current solutions that use expression trees to get the property name.
An example of the solutions I have been seeing.
public static string GetPropertyName<T, TReturn>(Expression<Func<T, TReturn>> expression) { MemberExpression body = (MemberExpression)expression.Body; return body.Member.Name; } Cheers
public static string GetPropertyName<T, TReturn>(Expression<Func<T, TReturn>> expression) { MemberExpression body = (MemberExpression)expression.Body; return body.Member.Name; }