DateInfoStruct.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Masuit.Tools.DateTimeExt
  4. {
  5. /// <summary>
  6. /// 日期信息
  7. /// </summary>
  8. public readonly record struct DateInfoStruct : IEquatable<DateInfoStruct>
  9. {
  10. /// <summary>
  11. /// 月
  12. /// </summary>
  13. public readonly int Month;
  14. /// <summary>
  15. /// 日
  16. /// </summary>
  17. public readonly int Day;
  18. /// <summary>
  19. /// 假期长度
  20. /// </summary>
  21. public readonly int Recess;
  22. /// <summary>
  23. /// 节假日名
  24. /// </summary>
  25. public readonly string HolidayName;
  26. /// <summary>
  27. /// 日期信息
  28. /// </summary>
  29. /// <param name="month"></param>
  30. /// <param name="day"></param>
  31. /// <param name="recess"></param>
  32. /// <param name="name"></param>
  33. public DateInfoStruct(int month, int day, int recess, string name)
  34. {
  35. Month = month;
  36. Day = day;
  37. Recess = recess;
  38. HolidayName = name;
  39. }
  40. /// <summary>指示当前对象是否等于同一类型的另一个对象。</summary>
  41. /// <param name="other">一个与此对象进行比较的对象。</param>
  42. /// <returns>如果当前对象等于 <paramref name="other" /> 参数,则为 true;否则为 false。</returns>
  43. public bool Equals(DateInfoStruct other)
  44. {
  45. return Month == other.Month && Day == other.Day && Recess == other.Recess && HolidayName == other.HolidayName;
  46. }
  47. /// <summary>返回此实例的哈希代码。</summary>
  48. /// <returns>一个 32 位带符号整数,它是此实例的哈希代码。</returns>
  49. public override int GetHashCode()
  50. {
  51. unchecked
  52. {
  53. var hashCode = Month;
  54. hashCode = (hashCode * 397) ^ Day;
  55. hashCode = (hashCode * 397) ^ Recess;
  56. hashCode = (hashCode * 397) ^ (HolidayName != null ? HolidayName.GetHashCode() : 0);
  57. return hashCode;
  58. }
  59. }
  60. }
  61. }