using System; using System.Linq.Expressions; namespace XHWK.Model { /// /// singba:20120807 /// 这个基类只作为INotifyPropertyChanged的实现,不再是Entity的基类 /// public class EntityBase : System.ComponentModel.INotifyPropertyChanged { #region INotifyPropertyChanged Members public virtual event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; protected virtual void RaisePropertyChanged(string name) { if (PropertyChanged != null) { PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(name)); } } protected virtual void RaisePropertyChanged(Expression> property) { LambdaExpression lambda = property; MemberExpression memberExpression; if (lambda.Body is UnaryExpression) { UnaryExpression unaryExpression = (UnaryExpression)lambda.Body; memberExpression = (MemberExpression)unaryExpression.Operand; } else { memberExpression = (MemberExpression)lambda.Body; } RaisePropertyChanged(memberExpression.Member.Name); } #endregion INotifyPropertyChanged Members } }