1
1
懒得勤快 1 жил өмнө
parent
commit
b32210192d

+ 27 - 2
Masuit.Tools.Abstractions/DateTimeExt/DateInfoStruct.cs

@@ -1,9 +1,12 @@
-namespace Masuit.Tools.DateTimeExt
+using System;
+using System.Collections.Generic;
+
+namespace Masuit.Tools.DateTimeExt
 {
     /// <summary>
     /// 日期信息
     /// </summary>
-    public struct DateInfoStruct
+    public readonly record struct DateInfoStruct : IEquatable<DateInfoStruct>
     {
         /// <summary>
         /// 月
@@ -39,5 +42,27 @@
             Recess = recess;
             HolidayName = name;
         }
+
+        /// <summary>指示当前对象是否等于同一类型的另一个对象。</summary>
+        /// <param name="other">一个与此对象进行比较的对象。</param>
+        /// <returns>如果当前对象等于 <paramref name="other" /> 参数,则为 true;否则为 false。</returns>
+        public bool Equals(DateInfoStruct other)
+        {
+            return Month == other.Month && Day == other.Day && Recess == other.Recess && HolidayName == other.HolidayName;
+        }
+
+        /// <summary>返回此实例的哈希代码。</summary>
+        /// <returns>一个 32 位带符号整数,它是此实例的哈希代码。</returns>
+        public override int GetHashCode()
+        {
+            unchecked
+            {
+                var hashCode = Month;
+                hashCode = (hashCode * 397) ^ Day;
+                hashCode = (hashCode * 397) ^ Recess;
+                hashCode = (hashCode * 397) ^ (HolidayName != null ? HolidayName.GetHashCode() : 0);
+                return hashCode;
+            }
+        }
     }
 }

+ 5 - 2
Masuit.Tools.Abstractions/DateTimeExt/DateTimeHelper.cs

@@ -1,4 +1,4 @@
-using System;
+using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Globalization;
@@ -67,7 +67,7 @@ namespace Masuit.Tools.DateTimeExt
         private static extern bool SetLocalTime(ref SystemTime time);
 
         [StructLayout(LayoutKind.Sequential)]
-        private struct SystemTime
+        private record struct SystemTime
         {
             public short year;
             public short month;
@@ -391,6 +391,9 @@ namespace Masuit.Tools.DateTimeExt
         }
     }
 
+    /// <summary>
+    ///
+    /// </summary>
     public interface ITimePeriod
     {
         /// <summary>

+ 26 - 2
Masuit.Tools.Abstractions/DateTimeExt/WeekHolidayStruct.cs

@@ -1,9 +1,11 @@
-namespace Masuit.Tools.DateTimeExt
+using System;
+
+namespace Masuit.Tools.DateTimeExt
 {
     /// <summary>
     /// 节假日信息
     /// </summary>
-    public struct WeekHolidayStruct
+    public readonly record struct WeekHolidayStruct : IEquatable<WeekHolidayStruct>
     {
         /// <summary>
         /// 月
@@ -39,5 +41,27 @@
             WeekDay = weekDay;
             HolidayName = name;
         }
+
+        /// <summary>指示当前对象是否等于同一类型的另一个对象。</summary>
+        /// <param name="other">一个与此对象进行比较的对象。</param>
+        /// <returns>如果当前对象等于 <paramref name="other" /> 参数,则为 true;否则为 false。</returns>
+        public bool Equals(WeekHolidayStruct other)
+        {
+            return Month == other.Month && WeekAtMonth == other.WeekAtMonth && WeekDay == other.WeekDay && HolidayName == other.HolidayName;
+        }
+
+        /// <summary>返回此实例的哈希代码。</summary>
+        /// <returns>一个 32 位带符号整数,它是此实例的哈希代码。</returns>
+        public override int GetHashCode()
+        {
+            unchecked
+            {
+                var hashCode = Month;
+                hashCode = (hashCode * 397) ^ WeekAtMonth;
+                hashCode = (hashCode * 397) ^ WeekDay;
+                hashCode = (hashCode * 397) ^ (HolidayName != null ? HolidayName.GetHashCode() : 0);
+                return hashCode;
+            }
+        }
     }
 }

+ 25 - 3
Masuit.Tools.Abstractions/Files/FileDetector/AbstractSignatureDetector.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Reflection;
@@ -8,7 +9,7 @@ using Masuit.Tools.Mime;
 namespace Masuit.Tools.Files.FileDetector;
 
 [StructLayout(LayoutKind.Sequential)]
-public struct SignatureInformation
+public record struct SignatureInformation : IEquatable<SignatureInformation>
 {
     /// <summary>
     ///
@@ -24,6 +25,27 @@ public struct SignatureInformation
     ///
     /// </summary>
     public byte[] Presignature;
+
+    /// <summary>指示当前对象是否等于同一类型的另一个对象。</summary>
+    /// <param name="other">一个与此对象进行比较的对象。</param>
+    /// <returns>如果当前对象等于 <paramref name="other" /> 参数,则为 true;否则为 false。</returns>
+    public bool Equals(SignatureInformation other)
+    {
+        return Position == other.Position && Signature.SequenceEqual(other.Signature) && Presignature.SequenceEqual(other.Presignature);
+    }
+
+    /// <summary>返回此实例的哈希代码。</summary>
+    /// <returns>一个 32 位带符号整数,它是此实例的哈希代码。</returns>
+    public override int GetHashCode()
+    {
+        unchecked
+        {
+            var hashCode = Position;
+            hashCode = (hashCode * 397) ^ (Signature != null ? Signature.GetHashCode() : 0);
+            hashCode = (hashCode * 397) ^ (Presignature != null ? Presignature.GetHashCode() : 0);
+            return hashCode;
+        }
+    }
 }
 
 public abstract class AbstractSignatureDetector : IDetector
@@ -96,4 +118,4 @@ public abstract class AbstractSignatureDetector : IDetector
         }
         return !failed;
     }
-}
+}

+ 11 - 14
Masuit.Tools.Abstractions/Systems/NullObject.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 
 namespace Masuit.Tools.Systems;
 
@@ -6,7 +7,7 @@ namespace Masuit.Tools.Systems;
 /// 可空对象
 /// </summary>
 /// <typeparam name="T"></typeparam>
-public readonly record struct NullObject<T> : IComparable, IComparable<T>
+public readonly record struct NullObject<T> : IComparable, IComparable<T>, IEquatable<NullObject<T>>
 {
     public NullObject()
     {
@@ -77,18 +78,14 @@ public readonly record struct NullObject<T> : IComparable, IComparable<T>
 
     public override int GetHashCode()
     {
-        if (Item.IsDefaultValue())
-        {
-            return 0;
-        }
-
-        var result = Item.GetHashCode();
-
-        if (result >= 0)
-        {
-            result++;
-        }
+        return EqualityComparer<T>.Default.GetHashCode(Item);
+    }
 
-        return result;
+    /// <summary>指示当前对象是否等于同一类型的另一个对象。</summary>
+    /// <param name="other">一个与此对象进行比较的对象。</param>
+    /// <returns>如果当前对象等于 <paramref name="other" /> 参数,则为 true;否则为 false。</returns>
+    public bool Equals(NullObject<T> other)
+    {
+        return EqualityComparer<T>.Default.Equals(Item, other.Item);
     }
-}
+}

+ 1 - 1
Masuit.Tools.Excel/Masuit.Tools.Excel.csproj

@@ -37,7 +37,7 @@
       </None>
     </ItemGroup>
     <ItemGroup>
-        <PackageReference Include="EPPlus" Version="7.1.3" />
+        <PackageReference Include="EPPlus" Version="7.2.0" />
         <PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
     </ItemGroup>
     <ItemGroup>

+ 1 - 1
Masuit.Tools.NoSQL.MongoDBClient/Masuit.Tools.NoSQL.MongoDBClient.csproj

@@ -38,7 +38,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="MongoDB.Driver" Version="2.25.0" />
+    <PackageReference Include="MongoDB.Driver" Version="2.26.0" />
   </ItemGroup>
 
 </Project>

+ 23 - 3
Masuit.Tools/Mvc/Internal/ByteRange.cs

@@ -1,8 +1,28 @@
-namespace Masuit.Tools.Mvc.Internal
+using System;
+
+namespace Masuit.Tools.Mvc.Internal
 {
-    public struct ByteRange
+    public record struct ByteRange : IEquatable<ByteRange>
     {
         public long Start { get; set; }
         public long End { get; set; }
+
+        /// <summary>指示当前对象是否等于同一类型的另一个对象。</summary>
+        /// <param name="other">一个与此对象进行比较的对象。</param>
+        /// <returns>如果当前对象等于 <paramref name="other" /> 参数,则为 true;否则为 false。</returns>
+        public bool Equals(ByteRange other)
+        {
+            return Start == other.Start && End == other.End;
+        }
+
+        /// <summary>返回此实例的哈希代码。</summary>
+        /// <returns>一个 32 位带符号整数,它是此实例的哈希代码。</returns>
+        public override int GetHashCode()
+        {
+            unchecked
+            {
+                return (Start.GetHashCode() * 397) ^ End.GetHashCode();
+            }
+        }
     }
-}
+}