Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
// Read more about this class at http://clariusconsulting.net/kzu [DebuggerStepThrough] public abstract class ViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged = (sender, args) => { }; protected ViewModel() { } protected void RaiseChanged<TProperty>(Expression<Func<TProperty>> propertyExpresion) { var property = propertyExpresion.Body as MemberExpression; if (property == null || !(property.Member is PropertyInfo) || !IsPropertyOfThis(property)) { throw new ArgumentException(string.Format( CultureInfo.CurrentCulture, "Expression must be of the form 'this.PropertyName'. Invalid expression '{0}'.", propertyExpresion), "propertyExpression"); } this.OnPropertyChanged(property.Member.Name); } private bool IsPropertyOfThis(MemberExpression property) { var constant = RemoveCast(property.Expression) as ConstantExpression; return constant != null && constant.Value == this; } private Expression RemoveCast(Expression expression) { if (expression.NodeType == ExpressionType.Convert || expression.NodeType == ExpressionType.ConvertChecked) return ((UnaryExpression)expression).Operand; return expression; } protected virtual void OnPropertyChanged(string propertyName) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } }
This paste will be private.
From the Design Piracy series on my blog: