懒得勤快 1 рік тому
батько
коміт
0ca9e96e90

+ 19 - 4
Masuit.Tools.Abstractions/Extensions/BaseType/ObjectExtensions.cs

@@ -7,6 +7,9 @@ using System.Reflection;
 using Masuit.Tools.Dynamics;
 using Masuit.Tools.Reflection;
 using Newtonsoft.Json.Linq;
+using System.Text.Json;
+using Masuit.Tools.Systems;
+using JsonSerializer = System.Text.Json.JsonSerializer;
 
 namespace Masuit.Tools;
 
@@ -106,10 +109,11 @@ public static class ObjectExtensions
     /// 深克隆
     /// </summary>
     /// <param name="originalObject"></param>
+    /// <param name="useJson">使用json方式</param>
     /// <returns></returns>
-    public static object DeepClone(this object originalObject)
+    public static object DeepClone(this object originalObject, bool useJson = false)
     {
-        return InternalCopy(originalObject, new Dictionary<object, object>(new ReferenceEqualityComparer()));
+        return useJson ? InternalJsonCopy(originalObject) : InternalCopy(originalObject, new Dictionary<object, object>(new ReferenceEqualityComparer()));
     }
 
     /// <summary>
@@ -117,10 +121,21 @@ public static class ObjectExtensions
     /// </summary>
     /// <typeparam name="T"></typeparam>
     /// <param name="original"></param>
+    /// <param name="useJson">使用json方式</param>
     /// <returns></returns>
-    public static T DeepClone<T>(this T original)
+    public static T DeepClone<T>(this T original, bool useJson = false)
     {
-        return (T)DeepClone((object)original);
+        return useJson ? InternalJsonCopy(original) : (T)InternalCopy(original, new Dictionary<object, object>(new ReferenceEqualityComparer()));
+    }
+
+    private static T InternalJsonCopy<T>(T obj)
+    {
+        using var stream = new PooledMemoryStream();
+        using var writer = new Utf8JsonWriter(stream);
+        JsonSerializer.Serialize(writer, obj);
+        writer.Flush();
+        var reader = new Utf8JsonReader(stream.ToArray());
+        return JsonSerializer.Deserialize<T>(ref reader);
     }
 
     private static object InternalCopy(object originalObject, IDictionary<object, object> visited)

+ 13 - 13
Masuit.Tools.Abstractions/Extensions/BaseType/StringExtensions.cs

@@ -13,6 +13,7 @@ using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading;
 using System.Threading.Tasks;
+using Masuit.Tools.Security;
 
 namespace Masuit.Tools
 {
@@ -703,7 +704,8 @@ namespace Masuit.Tools
         /// <returns></returns>
         public static string Crc32(this string s)
         {
-            return string.Join(string.Empty, new Security.Crc32().ComputeHash(Encoding.UTF8.GetBytes(s)).Select(b => b.ToString("x2")));
+            using var crc32 = new Crc32();
+            return string.Join(string.Empty, crc32.ComputeHash(Encoding.UTF8.GetBytes(s)).Select(b => b.ToString("x2")));
         }
 
         /// <summary>
@@ -713,7 +715,8 @@ namespace Masuit.Tools
         /// <returns></returns>
         public static string Crc64(this string s)
         {
-            return string.Join(string.Empty, new Security.Crc64().ComputeHash(Encoding.UTF8.GetBytes(s)).Select(b => b.ToString("x2")));
+            using var crc64 = new Crc64();
+            return string.Join(string.Empty, crc64.ComputeHash(Encoding.UTF8.GetBytes(s)).Select(b => b.ToString("x2")));
         }
 
         #endregion Crc32
@@ -731,7 +734,7 @@ namespace Masuit.Tools
         /// <returns>是否匹配成功</returns>
         public static bool MatchCNPatentNumber(this string patnum)
         {
-            Regex patnumWithCheckbitPattern = new Regex(@"^
+            var patnumWithCheckbitPattern = new Regex(@"^
 (?<!\d)
 (?<patentnum>
     (?<basenum>
@@ -748,7 +751,7 @@ namespace Masuit.Tools
 )
 (?!\d)
 $", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOptions.Multiline);
-            Match m = patnumWithCheckbitPattern.Match(patnum);
+            var m = patnumWithCheckbitPattern.Match(patnum);
             if (!m.Success)
             {
                 return false;
@@ -758,10 +761,10 @@ $", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOption
             patnum = patnum.ToUpper().Replace(".", "");
             if (patnum.Length == 9 || patnum.Length == 8)
             {
-                byte[] factors8 = new byte[] { 2, 3, 4, 5, 6, 7, 8, 9 };
+                byte[] factors8 = { 2, 3, 4, 5, 6, 7, 8, 9 };
                 int year = Convert.ToUInt16(patnum.Substring(0, 2));
-                year += (year >= 85) ? (ushort)1900u : (ushort)2000u;
-                if (year >= 1985 || year <= 2003)
+                year += year >= 85 ? (ushort)1900u : (ushort)2000u;
+                if (year is >= 1985 or <= 2003)
                 {
                     int sum = 0;
                     for (byte i = 0; i < 8; i++)
@@ -770,12 +773,9 @@ $", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOption
                     }
 
                     char checkbit = "0123456789X"[sum % 11];
-                    if (patnum.Length == 9)
+                    if (patnum.Length == 9 && checkbit != patnum[8])
                     {
-                        if (checkbit != patnum[8])
-                        {
-                            isPatnumTrue = false;
-                        }
+                        isPatnumTrue = false;
                     }
                 }
                 else
@@ -783,7 +783,7 @@ $", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase | RegexOption
                     isPatnumTrue = false;
                 }
             }
-            else if (patnum.Length == 13 || patnum.Length == 12)
+            else if (patnum.Length is 13 or 12)
             {
                 byte[] factors12 = { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5 };
                 int year = Convert.ToUInt16(patnum.Substring(0, 4));

+ 48 - 33
Masuit.Tools.Abstractions/Hardware/SystemInfo.cs

@@ -30,15 +30,12 @@ namespace Masuit.Tools.Hardware
         private const int WsBorder = 8388608;
         private static readonly PerformanceCounter PcCpuLoad; //CPU计数器
 
-        private static readonly PerformanceCounter MemoryCounter;
-        private static readonly PerformanceCounter CpuCounter;
-        private static readonly PerformanceCounter DiskReadCounter;
-        private static readonly PerformanceCounter DiskWriteCounter;
+        private static readonly PerformanceCounter IOCounter;
 
         private static readonly string[] InstanceNames = { };
         private static readonly PerformanceCounter[] NetRecvCounters;
         private static readonly PerformanceCounter[] NetSentCounters;
-        private static readonly Dictionary<string, dynamic> _cache = new();
+        private static readonly Dictionary<string, dynamic> Cache = new();
 
         public static bool IsWinPlatform => Environment.OSVersion.Platform is PlatformID.Win32Windows
             or PlatformID.Win32S or PlatformID.WinCE or PlatformID.Win32NT;
@@ -54,10 +51,7 @@ namespace Masuit.Tools.Hardware
         {
             if (IsWinPlatform)
             {
-                MemoryCounter = new PerformanceCounter();
-                CpuCounter = new PerformanceCounter();
-                DiskReadCounter = new PerformanceCounter();
-                DiskWriteCounter = new PerformanceCounter();
+                IOCounter = new PerformanceCounter();
 
                 //初始化CPU计数器
                 PcCpuLoad = new PerformanceCounter("Processor", "% Processor Time", "_Total")
@@ -144,7 +138,7 @@ namespace Masuit.Tools.Hardware
         /// <returns></returns>
         public static string GetProcessorData()
         {
-            var d = GetCounterValue(CpuCounter, "Processor", "% Processor Time", "_Total");
+            var d = GetCounterValue(IOCounter, "Processor", "% Processor Time", "_Total");
             return CompactFormat ? (int)d + "%" : d.ToString("F") + "%";
         }
 
@@ -186,7 +180,7 @@ namespace Masuit.Tools.Hardware
         {
             try
             {
-                return _cache.GetOrAdd(nameof(GetCpuCount), () =>
+                return Cache.GetOrAdd(nameof(GetCpuCount), () =>
                 {
                     if (!IsWinPlatform)
                     {
@@ -281,6 +275,16 @@ namespace Masuit.Tools.Hardware
         /// </summary>
         public static long PhysicalMemory { get; }
 
+        public static long CurrentProcessMemory
+        {
+            get
+            {
+                if (!IsWinPlatform) return 0;
+                using var process = Process.GetCurrentProcess();
+                return (long)GetCounterValue(IOCounter, "Process", "Working Set - Private", process.ProcessName);
+            }
+        }
+
         /// <summary>
         /// 获取内存信息
         /// </summary>
@@ -304,11 +308,12 @@ namespace Masuit.Tools.Hardware
         /// <returns></returns>
         public static string GetMemoryVData()
         {
-            float d = GetCounterValue(MemoryCounter, "Memory", "% Committed Bytes In Use", null);
+            if (!IsWinPlatform) return "";
+            float d = GetCounterValue(IOCounter, "Memory", "% Committed Bytes In Use", null);
             var str = d.ToString("F") + "% (";
-            d = GetCounterValue(MemoryCounter, "Memory", "Committed Bytes", null);
+            d = GetCounterValue(IOCounter, "Memory", "Committed Bytes", null);
             str += FormatBytes(d) + " / ";
-            d = GetCounterValue(MemoryCounter, "Memory", "Commit Limit", null);
+            d = GetCounterValue(IOCounter, "Memory", "Commit Limit", null);
             return str + FormatBytes(d) + ") ";
         }
 
@@ -318,7 +323,8 @@ namespace Masuit.Tools.Hardware
         /// <returns></returns>
         public static float GetUsageVirtualMemory()
         {
-            return GetCounterValue(MemoryCounter, "Memory", "% Committed Bytes In Use", null);
+            if (!IsWinPlatform) return 0;
+            return GetCounterValue(IOCounter, "Memory", "% Committed Bytes In Use", null);
         }
 
         /// <summary>
@@ -327,7 +333,8 @@ namespace Masuit.Tools.Hardware
         /// <returns></returns>
         public static float GetUsedVirtualMemory()
         {
-            return GetCounterValue(MemoryCounter, "Memory", "Committed Bytes", null);
+            if (!IsWinPlatform) return 0;
+            return GetCounterValue(IOCounter, "Memory", "Committed Bytes", null);
         }
 
         /// <summary>
@@ -336,7 +343,8 @@ namespace Masuit.Tools.Hardware
         /// <returns></returns>
         public static float GetTotalVirtualMemory()
         {
-            return GetCounterValue(MemoryCounter, "Memory", "Commit Limit", null);
+            if (!IsWinPlatform) return 0;
+            return GetCounterValue(IOCounter, "Memory", "Commit Limit", null);
         }
 
         /// <summary>
@@ -345,11 +353,12 @@ namespace Masuit.Tools.Hardware
         /// <returns></returns>
         public static string GetMemoryPData()
         {
+            if (!IsWinPlatform) return "";
             string s = QueryComputerSystem("totalphysicalmemory");
             if (string.IsNullOrEmpty(s)) return "";
 
             var totalphysicalmemory = Convert.ToSingle(s);
-            var d = GetCounterValue(MemoryCounter, "Memory", "Available Bytes", null);
+            var d = GetCounterValue(IOCounter, "Memory", "Available Bytes", null);
             d = totalphysicalmemory - d;
             s = CompactFormat ? "%" : "% (" + FormatBytes(d) + " / " + FormatBytes(totalphysicalmemory) + ")";
             d /= totalphysicalmemory;
@@ -363,7 +372,7 @@ namespace Masuit.Tools.Hardware
         /// <returns></returns>
         public static float GetTotalPhysicalMemory()
         {
-            return _cache.GetOrAdd(nameof(GetTotalPhysicalMemory), () =>
+            return Cache.GetOrAdd(nameof(GetTotalPhysicalMemory), () =>
             {
                 var s = QueryComputerSystem("totalphysicalmemory");
                 return s.TryConvertTo<float>();
@@ -376,7 +385,8 @@ namespace Masuit.Tools.Hardware
         /// <returns></returns>
         public static float GetFreePhysicalMemory()
         {
-            return GetCounterValue(MemoryCounter, "Memory", "Available Bytes", null);
+            if (!IsWinPlatform) return 0;
+            return GetCounterValue(IOCounter, "Memory", "Available Bytes", null);
         }
 
         /// <summary>
@@ -397,15 +407,19 @@ namespace Masuit.Tools.Hardware
         /// </summary>
         /// <param name="dd">读或写</param>
         /// <returns></returns>
-        public static float GetDiskData(DiskData dd) => dd switch
+        public static float GetDiskData(DiskData dd)
         {
-            DiskData.Read => GetCounterValue(DiskReadCounter, "PhysicalDisk", "Disk Read Bytes/sec", "_Total"),
-            DiskData.Write => GetCounterValue(DiskWriteCounter, "PhysicalDisk", "Disk Write Bytes/sec", "_Total"),
-            DiskData.ReadAndWrite => GetCounterValue(DiskReadCounter, "PhysicalDisk", "Disk Read Bytes/sec", "_Total") + GetCounterValue(DiskWriteCounter, "PhysicalDisk", "Disk Write Bytes/sec", "_Total"),
-            _ => 0
-        };
+            if (!IsWinPlatform) return 0;
+            return dd switch
+            {
+                DiskData.Read => GetCounterValue(IOCounter, "PhysicalDisk", "Disk Read Bytes/sec", "_Total"),
+                DiskData.Write => GetCounterValue(IOCounter, "PhysicalDisk", "Disk Write Bytes/sec", "_Total"),
+                DiskData.ReadAndWrite => GetCounterValue(IOCounter, "PhysicalDisk", "Disk Read Bytes/sec", "_Total") + GetCounterValue(IOCounter, "PhysicalDisk", "Disk Write Bytes/sec", "_Total"),
+                _ => 0
+            };
+        }
 
-        private static readonly List<DiskInfo> DiskInfos = new();
+        private static readonly List<DiskInfo> DiskInfos = [];
 
         /// <summary>
         /// 获取磁盘可用空间
@@ -454,6 +468,7 @@ namespace Masuit.Tools.Hardware
         /// <returns></returns>
         public static float GetNetData(NetData nd)
         {
+            if (!IsWinPlatform) return 0;
             if (InstanceNames is { Length: 0 }) return 0;
 
             float d = 0;
@@ -495,7 +510,7 @@ namespace Masuit.Tools.Hardware
             {
                 if (!IsWinPlatform) return new List<string>();
 
-                return _cache.GetOrAdd(nameof(GetMacAddress), () =>
+                return Cache.GetOrAdd(nameof(GetMacAddress), () =>
                 {
                     IList<string> list = new List<string>();
                     using var mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
@@ -530,7 +545,7 @@ namespace Masuit.Tools.Hardware
             {
                 if (!IsWinPlatform) return "";
 
-                return _cache.GetOrAdd(nameof(GetIPAddressWMI), () =>
+                return Cache.GetOrAdd(nameof(GetIPAddressWMI), () =>
                 {
                     using var mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                     using var moc = mc.GetInstances();
@@ -592,7 +607,7 @@ namespace Masuit.Tools.Hardware
             {
                 if (!IsWinPlatform) return "";
 
-                return _cache.GetOrAdd(nameof(GetNetworkCardAddress), () =>
+                return Cache.GetOrAdd(nameof(GetNetworkCardAddress), () =>
                 {
                     using var mos = new ManagementObjectSearcher("select * from Win32_NetworkAdapter where ((MACAddress Is Not NULL) and (Manufacturer <> 'Microsoft'))");
                     using var moc = mos.Get();
@@ -707,7 +722,7 @@ namespace Masuit.Tools.Hardware
         {
             try
             {
-                return _cache.GetOrAdd(nameof(GetSystemType), () =>
+                return Cache.GetOrAdd(nameof(GetSystemType), () =>
                 {
                     if (!IsWinPlatform)
                     {
@@ -745,7 +760,7 @@ namespace Masuit.Tools.Hardware
             {
                 if (!IsWinPlatform) return "";
 
-                return _cache.GetOrAdd(nameof(GetBiosSerialNumber), () =>
+                return Cache.GetOrAdd(nameof(GetBiosSerialNumber), () =>
                 {
                     using var searcher = new ManagementObjectSearcher("select * from Win32_BIOS");
                     using var mos = searcher.Get();
@@ -772,7 +787,7 @@ namespace Masuit.Tools.Hardware
         {
             if (!IsWinPlatform) return new BiosInfo();
 
-            return _cache.GetOrAdd(nameof(GetBiosInfo), () =>
+            return Cache.GetOrAdd(nameof(GetBiosInfo), () =>
             {
                 using var searcher = new ManagementObjectSearcher("select * from Win32_BaseBoard");
                 using var mos = searcher.Get();

+ 95 - 91
Masuit.Tools.Abstractions/Security/Crc32.cs

@@ -2,126 +2,130 @@
 using System.Collections.Generic;
 using System.Security.Cryptography;
 
-namespace Masuit.Tools.Security
+namespace Masuit.Tools.Security;
+
+/// <summary>
+/// 实现一个32位CRC哈希算法(兼容Zip)
+/// </summary>
+/// <remarks>
+/// Crc32仅应用于与旧文件格式和算法向后兼容。 对于新的应用程序,它不够安全。 如果需要多次调用同一数据,请使用HashAlgorithm接口
+/// </remarks>
+public sealed class Crc32 : HashAlgorithm
 {
-    /// <summary>
-    /// 实现一个32位CRC哈希算法(兼容Zip)
-    /// </summary>
-    /// <remarks>
-    /// Crc32仅应用于与旧文件格式和算法向后兼容。 对于新的应用程序,它不够安全。 如果需要多次调用同一数据,请使用HashAlgorithm接口
-    /// </remarks>
-    public sealed class Crc32 : HashAlgorithm
+    ~Crc32()
     {
-        public const uint DefaultPolynomial = 0xedb88320u;
-        public const uint DefaultSeed = 0xffffffffu;
-        private static uint[] _defaultTable;
-        private readonly uint _seed;
-        private readonly uint[] _table;
-        private uint _hash;
+        Dispose();
+    }
+
+    public const uint DefaultPolynomial = 0xedb88320u;
+    public const uint DefaultSeed = 0xffffffffu;
+    private static uint[] _defaultTable;
+    private readonly uint _seed;
+    private readonly uint[] _table;
+    private uint _hash;
 
-        public override int HashSize => 32;
+    public override int HashSize => 32;
+
+    public Crc32() : this(DefaultPolynomial, DefaultSeed)
+    {
+    }
 
-        public Crc32() : this(DefaultPolynomial, DefaultSeed)
+    public Crc32(uint polynomial, uint seed)
+    {
+        if (!BitConverter.IsLittleEndian)
         {
+            throw new PlatformNotSupportedException("Big Endian 处理程序不支持");
         }
 
-        public Crc32(uint polynomial, uint seed)
-        {
-            if (!BitConverter.IsLittleEndian)
-            {
-                throw new PlatformNotSupportedException("Big Endian 处理程序不支持");
-            }
+        _table = InitializeTable(polynomial);
+        _seed = _hash = seed;
+    }
 
-            _table = InitializeTable(polynomial);
-            _seed = _hash = seed;
-        }
+    public override void Initialize()
+    {
+        _hash = _seed;
+    }
 
-        public override void Initialize()
-        {
-            _hash = _seed;
-        }
+    protected override void HashCore(byte[] array, int ibStart, int cbSize)
+    {
+        _hash = CalculateHash(_table, _hash, array, ibStart, cbSize);
+    }
 
-        protected override void HashCore(byte[] array, int ibStart, int cbSize)
-        {
-            _hash = CalculateHash(_table, _hash, array, ibStart, cbSize);
-        }
+    protected override byte[] HashFinal()
+    {
+        var hashBuffer = UInt32ToBigEndianBytes(~_hash);
+        HashValue = hashBuffer;
+        return hashBuffer;
+    }
 
-        protected override byte[] HashFinal()
-        {
-            var hashBuffer = UInt32ToBigEndianBytes(~_hash);
-            HashValue = hashBuffer;
-            return hashBuffer;
-        }
+    public static uint Compute(byte[] buffer)
+    {
+        return Compute(DefaultSeed, buffer);
+    }
 
-        public static uint Compute(byte[] buffer)
-        {
-            return Compute(DefaultSeed, buffer);
-        }
+    public static uint Compute(uint seed, byte[] buffer)
+    {
+        return Compute(DefaultPolynomial, seed, buffer);
+    }
 
-        public static uint Compute(uint seed, byte[] buffer)
-        {
-            return Compute(DefaultPolynomial, seed, buffer);
-        }
+    public static uint Compute(uint polynomial, uint seed, byte[] buffer)
+    {
+        return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length);
+    }
 
-        public static uint Compute(uint polynomial, uint seed, byte[] buffer)
+    private static uint[] InitializeTable(uint polynomial)
+    {
+        if (polynomial == DefaultPolynomial && _defaultTable != null)
         {
-            return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length);
+            return _defaultTable;
         }
 
-        private static uint[] InitializeTable(uint polynomial)
+        var createTable = new uint[256];
+        for (uint i = 0; i < 256; i++)
         {
-            if (polynomial == DefaultPolynomial && _defaultTable != null)
-            {
-                return _defaultTable;
-            }
-
-            var createTable = new uint[256];
-            for (uint i = 0; i < 256; i++)
+            var entry = i;
+            for (var j = 0; j < 8; j++)
             {
-                var entry = i;
-                for (var j = 0; j < 8; j++)
+                if ((entry & 1) == 1)
                 {
-                    if ((entry & 1) == 1)
-                    {
-                        entry = (entry >> 1) ^ polynomial;
-                    }
-                    else
-                    {
-                        entry >>= 1;
-                    }
+                    entry = (entry >> 1) ^ polynomial;
+                }
+                else
+                {
+                    entry >>= 1;
                 }
-
-                createTable[i] = entry;
-            }
-
-            if (polynomial == DefaultPolynomial)
-            {
-                _defaultTable = createTable;
             }
 
-            return createTable;
+            createTable[i] = entry;
         }
 
-        private static uint CalculateHash(uint[] table, uint seed, IList<byte> buffer, int start, int size)
+        if (polynomial == DefaultPolynomial)
         {
-            var hash = seed;
-            for (var i = start; i < start + size; i++)
-            {
-                hash = (hash >> 8) ^ table[buffer[i] ^ hash & 0xff];
-            }
-
-            return hash;
+            _defaultTable = createTable;
         }
 
-        private static byte[] UInt32ToBigEndianBytes(uint uint32)
+        return createTable;
+    }
+
+    private static uint CalculateHash(uint[] table, uint seed, IList<byte> buffer, int start, int size)
+    {
+        var hash = seed;
+        for (var i = start; i < start + size; i++)
         {
-            var result = BitConverter.GetBytes(uint32);
-            if (BitConverter.IsLittleEndian)
-            {
-                Array.Reverse(result);
-            }
+            hash = (hash >> 8) ^ table[buffer[i] ^ hash & 0xff];
+        }
+
+        return hash;
+    }
 
-            return result;
+    private static byte[] UInt32ToBigEndianBytes(uint uint32)
+    {
+        var result = BitConverter.GetBytes(uint32);
+        if (BitConverter.IsLittleEndian)
+        {
+            Array.Reverse(result);
         }
+
+        return result;
     }
-}
+}

+ 103 - 98
Masuit.Tools.Abstractions/Security/Crc64.cs

@@ -2,134 +2,139 @@
 using System.Collections.Generic;
 using System.Security.Cryptography;
 
-namespace Masuit.Tools.Security
+namespace Masuit.Tools.Security;
+
+/// <summary>
+/// 64-bit CRC 实现
+/// </summary>
+/// <remarks>
+/// 支持ISO 3309标准
+/// </remarks>
+public class Crc64 : HashAlgorithm
 {
-    /// <summary>
-    /// 64-bit CRC 实现
-    /// </summary>
-    /// <remarks>
-    /// 支持ISO 3309标准
-    /// </remarks>
-    public class Crc64 : HashAlgorithm
+    ~Crc64()
     {
-        public const ulong DefaultSeed = 0x0;
-        private readonly ulong[] _table;
-        private readonly ulong _seed;
-        private ulong _hash;
-        internal static ulong[] Table;
-        public const ulong Iso3309Polynomial = 0xD800000000000000;
-        public override int HashSize => 64;
-
-        public Crc64() : this(Iso3309Polynomial)
-        {
-        }
+        Dispose();
+    }
 
-        public Crc64(ulong polynomial) : this(polynomial, DefaultSeed)
-        {
-        }
+    public const ulong DefaultSeed = 0x0;
+    private readonly ulong[] _table;
+    private readonly ulong _seed;
+    private ulong _hash;
+    internal static ulong[] Table;
+    public const ulong Iso3309Polynomial = 0xD800000000000000;
 
-        public Crc64(ulong polynomial, ulong seed)
-        {
-            if (!BitConverter.IsLittleEndian)
-            {
-                throw new PlatformNotSupportedException("Big Endian 处理程序不支持");
-            }
+    public override int HashSize => 64;
 
-            _table = InitializeTable(polynomial);
-            _seed = _hash = seed;
-        }
+    public Crc64() : this(Iso3309Polynomial)
+    {
+    }
 
-        public override void Initialize()
-        {
-            _hash = _seed;
-        }
+    public Crc64(ulong polynomial) : this(polynomial, DefaultSeed)
+    {
+    }
 
-        protected override void HashCore(byte[] array, int ibStart, int cbSize)
+    public Crc64(ulong polynomial, ulong seed)
+    {
+        if (!BitConverter.IsLittleEndian)
         {
-            _hash = CalculateHash(_hash, _table, array, ibStart, cbSize);
+            throw new PlatformNotSupportedException("Big Endian 处理程序不支持");
         }
 
-        protected override byte[] HashFinal()
-        {
-            var hashBuffer = UInt64ToBigEndianBytes(_hash);
-            HashValue = hashBuffer;
-            return hashBuffer;
-        }
+        _table = InitializeTable(polynomial);
+        _seed = _hash = seed;
+    }
 
-        protected static ulong CalculateHash(ulong seed, ulong[] table, IList<byte> buffer, int start, int size)
-        {
-            var hash = seed;
-            for (var i = start; i < start + size; i++)
-            {
-                unchecked
-                {
-                    hash = (hash >> 8) ^ table[(buffer[i] ^ hash) & 0xff];
-                }
-            }
+    public override void Initialize()
+    {
+        _hash = _seed;
+    }
 
-            return hash;
-        }
+    protected override void HashCore(byte[] array, int ibStart, int cbSize)
+    {
+        _hash = CalculateHash(_hash, _table, array, ibStart, cbSize);
+    }
+
+    protected override byte[] HashFinal()
+    {
+        var hashBuffer = UInt64ToBigEndianBytes(_hash);
+        HashValue = hashBuffer;
+        return hashBuffer;
+    }
 
-        private static byte[] UInt64ToBigEndianBytes(ulong value)
+    protected static ulong CalculateHash(ulong seed, ulong[] table, IList<byte> buffer, int start, int size)
+    {
+        var hash = seed;
+        for (var i = start; i < start + size; i++)
         {
-            var result = BitConverter.GetBytes(value);
-            if (BitConverter.IsLittleEndian)
+            unchecked
             {
-                Array.Reverse(result);
+                hash = (hash >> 8) ^ table[(buffer[i] ^ hash) & 0xff];
             }
-
-            return result;
         }
 
-        private static ulong[] InitializeTable(ulong polynomial)
+        return hash;
+    }
+
+    private static byte[] UInt64ToBigEndianBytes(ulong value)
+    {
+        var result = BitConverter.GetBytes(value);
+        if (BitConverter.IsLittleEndian)
         {
-            if (polynomial == Iso3309Polynomial && Table != null)
-            {
-                return Table;
-            }
+            Array.Reverse(result);
+        }
 
-            var createTable = CreateTable(polynomial);
-            if (polynomial == Iso3309Polynomial)
-            {
-                Table = createTable;
-            }
+        return result;
+    }
 
-            return createTable;
+    private static ulong[] InitializeTable(ulong polynomial)
+    {
+        if (polynomial == Iso3309Polynomial && Table != null)
+        {
+            return Table;
         }
 
-        protected static ulong[] CreateTable(ulong polynomial)
+        var createTable = CreateTable(polynomial);
+        if (polynomial == Iso3309Polynomial)
         {
-            var createTable = new ulong[256];
-            for (var i = 0; i < 256; ++i)
+            Table = createTable;
+        }
+
+        return createTable;
+    }
+
+    protected static ulong[] CreateTable(ulong polynomial)
+    {
+        var createTable = new ulong[256];
+        for (var i = 0; i < 256; ++i)
+        {
+            var entry = (ulong)i;
+            for (var j = 0; j < 8; ++j)
             {
-                var entry = (ulong)i;
-                for (var j = 0; j < 8; ++j)
+                if ((entry & 1) == 1)
                 {
-                    if ((entry & 1) == 1)
-                    {
-                        entry = (entry >> 1) ^ polynomial;
-                    }
-                    else
-                    {
-                        entry >>= 1;
-                    }
+                    entry = (entry >> 1) ^ polynomial;
+                }
+                else
+                {
+                    entry >>= 1;
                 }
-
-                createTable[i] = entry;
             }
 
-            return createTable;
+            createTable[i] = entry;
         }
 
-        public static ulong Compute(byte[] buffer)
-        {
-            return Compute(DefaultSeed, buffer);
-        }
+        return createTable;
+    }
 
-        public static ulong Compute(ulong seed, byte[] buffer)
-        {
-            Table ??= CreateTable(Iso3309Polynomial);
-            return CalculateHash(seed, Table, buffer, 0, buffer.Length);
-        }
+    public static ulong Compute(byte[] buffer)
+    {
+        return Compute(DefaultSeed, buffer);
+    }
+
+    public static ulong Compute(ulong seed, byte[] buffer)
+    {
+        Table ??= CreateTable(Iso3309Polynomial);
+        return CalculateHash(seed, Table, buffer, 0, buffer.Length);
     }
-}
+}