星火微课系统客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

EntityBase.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * author : singba singba@163.com
  3. * version : 20161221
  4. * source : AF.Core
  5. * license : free use or modify
  6. * description : 通用类型基类
  7. */
  8. using System;
  9. using System.Linq.Expressions;
  10. namespace ComeCapture.Models
  11. {
  12. /// <summary>
  13. /// singba:20120807
  14. /// 这个基类只作为INotifyPropertyChanged的实现,不再是Entity的基类
  15. /// </summary>
  16. public class EntityBase : System.ComponentModel.INotifyPropertyChanged
  17. {
  18. #region INotifyPropertyChanged Members
  19. public virtual event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
  20. protected virtual void RaisePropertyChanged(string name)
  21. {
  22. if (PropertyChanged != null)
  23. {
  24. // ReSharper disable once PolymorphicFieldLikeEventInvocation
  25. PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(name));
  26. }
  27. }
  28. protected virtual void RaisePropertyChanged<TProperty>(Expression<Func<TProperty>> property)
  29. {
  30. LambdaExpression lambda = property;
  31. MemberExpression memberExpression;
  32. if (lambda.Body is UnaryExpression)
  33. {
  34. UnaryExpression unaryExpression = (UnaryExpression)lambda.Body;
  35. memberExpression = (MemberExpression)unaryExpression.Operand;
  36. }
  37. else
  38. {
  39. memberExpression = (MemberExpression)lambda.Body;
  40. }
  41. RaisePropertyChanged(memberExpression.Member.Name);
  42. }
  43. #endregion INotifyPropertyChanged Members
  44. }
  45. }