LINQ Posts



Enhanced INotifyPropertyChanged - Revisited (Tuesday, September 09, 2008)

A while a go, I had a post regarding how to implement the INotifyPropertyChanged event in a more proper fashion. You didn't have to hard-code the property name, and could instead use a linq expression, which with a help of an extension method, the name of the property is easily extracted, and passed to raise the PropertyChanged event. Simple, right? public static class EventExtension{ public static void Notify<T, TValue>(this T instance, PropertyChangedEventHandler handler, Expression<Func<T, TValue>> selector) where T : INotifyPropertyChanged { if (handler != null) { var memberExpression = selector.Body as MemberExpression; if (memberExpression == null) throw new InvalidOperationException("selector should 
Filed under | 2 comments »



Enhanced INotifyPropertyChanged (Saturday, May 17, 2008)

Today, I found something very intresting regarding using of Linq Expressions. As you may know, binding objects in WPF required you to implement INotifyPropertyChanged interface (at least if you're using two-way binding). A typical implementation of this interface for Customer class would be :But, as Jafar Husain points on his blog you can benefit from Linq Expressions and C# 3.0 extension methods to handle this nicely without hard-coding property names in strings!Here's how it would look like with this technique :The magic is in "GetPropertySymbol" extension method, which extracts the member name from the Lambda expression. 
Filed under | 0 comments »