Browse Source

优化缓存中间件

懒得勤快 1 year ago
parent
commit
f0e71d7a67

+ 2 - 1
Masuit.Tools.Abstractions/Extensions/BaseType/ObjectExtensions.cs

@@ -71,7 +71,7 @@ namespace Masuit.Tools
                 sbyte s => s == 0,
                 short s => s == 0,
                 char s => s == 0,
-                bool s => s == false,
+                bool s => s,
                 ushort s => s == 0,
                 int s => s == 0,
                 uint s => s == 0,
@@ -83,6 +83,7 @@ namespace Masuit.Tools
                 Enum s => Equals(s, Enum.GetValues(value.GetType()).GetValue(0)),
                 DateTime s => s == DateTime.MinValue,
                 DateTimeOffset s => s == DateTimeOffset.MinValue,
+                Guid g => g == Guid.Empty,
                 _ => false
             };
         }

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

@@ -46,7 +46,7 @@
     </ItemGroup>
 
     <ItemGroup>
-        <PackageReference Include="AngleSharp" Version="1.0.6" />
+        <PackageReference Include="AngleSharp" Version="1.0.7" />
         <PackageReference Include="AngleSharp.Css" Version="1.0.0-alpha-99" />
         <PackageReference Include="Castle.Core" Version="5.1.1" />
         <PackageReference Include="DnsClient" Version="1.7.0" />

+ 7 - 43
Masuit.Tools.Abstractions/Systems/NullObject.cs

@@ -1,5 +1,4 @@
 using System;
-using System.ComponentModel;
 
 namespace Masuit.Tools.Systems;
 
@@ -7,25 +6,18 @@ namespace Masuit.Tools.Systems;
 /// 可空对象
 /// </summary>
 /// <typeparam name="T"></typeparam>
-public readonly struct NullObject<T> : IComparable, IComparable<T>
+public readonly record struct NullObject<T> : IComparable, IComparable<T>
 {
-    [DefaultValue(true)]
-    private readonly bool _isnull;
-
-    private NullObject(T item, bool isnull) : this()
+    public NullObject()
     {
-        _isnull = isnull;
-        Item = item;
     }
 
-    public NullObject(T item) : this(item, item == null)
+    public NullObject(T item)
     {
+        Item = item;
     }
 
-    public static NullObject<T> Null()
-    {
-        return new NullObject<T>();
-    }
+    public static NullObject<T> Null => new();
 
     public T Item { get; }
 
@@ -33,10 +25,7 @@ public readonly struct NullObject<T> : IComparable, IComparable<T>
     /// 是否是null
     /// </summary>
     /// <returns></returns>
-    public bool IsNull()
-    {
-        return _isnull;
-    }
+    public bool IsNull => Item.IsDefaultValue();
 
     /// <summary>
     /// 隐式转换
@@ -86,34 +75,9 @@ public readonly struct NullObject<T> : IComparable, IComparable<T>
         return Item.ToString().CompareTo(other.ToString());
     }
 
-    public override bool Equals(object obj)
-    {
-        if (obj == null)
-        {
-            return IsNull();
-        }
-
-        if (obj is not NullObject<T> nullObject)
-        {
-            return false;
-        }
-
-        if (IsNull())
-        {
-            return nullObject.IsNull();
-        }
-
-        if (nullObject.IsNull())
-        {
-            return false;
-        }
-
-        return Item.Equals(nullObject.Item);
-    }
-
     public override int GetHashCode()
     {
-        if (_isnull)
+        if (Item.IsDefaultValue())
         {
             return 0;
         }