WeekHolidayStruct.cs 2.1 KB

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