ChangePropertyInfo.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.ComponentModel;
  2. using System.Reflection;
  3. namespace Masuit.Tools.Core;
  4. /// <summary>
  5. /// 变更字段信息
  6. /// </summary>
  7. public class ChangePropertyInfo
  8. {
  9. /// <summary>
  10. /// 属性
  11. /// </summary>
  12. public PropertyInfo PropertyInfo { get; set; }
  13. /// <summary>
  14. /// 原始值
  15. /// </summary>
  16. public object OriginalValue { get; set; }
  17. /// <summary>
  18. /// 新值
  19. /// </summary>
  20. public object CurrentValue { get; set; }
  21. /// <summary>
  22. /// 是否是主键
  23. /// </summary>
  24. public bool IsPrimaryKey { get; set; }
  25. /// <summary>
  26. /// 是否是外键
  27. /// </summary>
  28. public bool IsForeignKey { get; set; }
  29. /// <summary>
  30. /// 变更描述格式化字符串
  31. /// </summary>
  32. public string ChangeDescription => $"{PropertyInfo.GetCustomAttribute<DescriptionAttribute>()?.Description ?? PropertyInfo.Name}:{OriginalValue} => {CurrentValue}";
  33. /// <summary>Returns a string that represents the current object.</summary>
  34. /// <returns>A string that represents the current object.</returns>
  35. public override string ToString()
  36. {
  37. return $"{ChangeDescription},字段:{PropertyInfo.Name},主键:{IsPrimaryKey},外键:{IsForeignKey}";
  38. }
  39. }