From 6432370f86731c7ad9817f9ca8f27e0efb7013fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Tue, 21 Apr 2026 20:43:32 +0800 Subject: [PATCH] =?UTF-8?q?ref:=20=E6=9B=B4=E6=96=B0=E5=88=B0=20C#=20?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E7=89=88=E6=9C=AC=2013=EF=BC=8C=E5=9B=9E?= =?UTF-8?q?=E6=BB=9A=20ArgumentReplace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Extensions/EnumerableExtensions.cs | 14 +++------ Extensions/StringExtensions.cs | 12 +++----- General/MsDelta.cs | 5 --- General/OneOf.cs | 4 +-- MeloongCore.csproj | 49 +++++++++++++++++++----------- Utils/DirectoryUtils.cs | 10 +----- Utils/MathUtils.cs | 10 ++---- Utils/PathUtils.cs | 7 +---- 8 files changed, 45 insertions(+), 66 deletions(-) diff --git a/Extensions/EnumerableExtensions.cs b/Extensions/EnumerableExtensions.cs index 137a689..ff279d0 100644 --- a/Extensions/EnumerableExtensions.cs +++ b/Extensions/EnumerableExtensions.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MeloongCore.Extensions; +namespace MeloongCore.Extensions; public static class EnumerableExtensions { #region Distinct @@ -133,7 +127,7 @@ public static class EnumerableExtensions { isFirst = false; else builder.Append(split); - if (element != null) builder.Append(element.ToString()); + if (element is not null) builder.Append(element.ToString()); } return builder.ToString(); } @@ -149,7 +143,7 @@ public static class EnumerableExtensions { isFirst = false; else builder.Append(split); - if (element != null) builder.Append(element.ToString()); + if (element is not null) builder.Append(element.ToString()); } return builder.ToString(); } @@ -160,7 +154,7 @@ public static class EnumerableExtensions { /// 判断集合是否有且仅有一个元素。 /// public static bool IsSingle(this IEnumerable source) { - if (source == null) return false; + if (source is null) return false; if (source is IList list) return list.Count == 1; using var enumerator = source.GetEnumerator(); if (!enumerator.MoveNext()) return false; diff --git a/Extensions/StringExtensions.cs b/Extensions/StringExtensions.cs index 81e1319..06490b4 100644 --- a/Extensions/StringExtensions.cs +++ b/Extensions/StringExtensions.cs @@ -1,8 +1,4 @@ -using System; -using System.Linq; -using System.Runtime.CompilerServices; - -namespace MeloongCore.Extensions; +namespace MeloongCore.Extensions; public static class StringExtensions { #region 区域性 / 大小写 简化 @@ -12,7 +8,7 @@ public static class StringExtensions { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool StartsWithF(this string value, string prefix, bool ignoreCase = false) { - if (value == null) return false; + if (value is null) return false; return value.StartsWith(prefix, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal); } /// @@ -20,7 +16,7 @@ public static class StringExtensions { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsWithF(this string value, string suffix, bool ignoreCase = false) { - if (value == null) return false; + if (value is null) return false; return value.EndsWith(suffix, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal); } @@ -85,7 +81,7 @@ public static class StringExtensions { if (splitStr.IsSingle()) return fullStr.Split(splitStr[0]); else - return fullStr.Split(new[] {splitStr}, StringSplitOptions.None); + return fullStr.Split([splitStr], StringSplitOptions.None); } /// diff --git a/General/MsDelta.cs b/General/MsDelta.cs index d4fd34d..ac3690c 100644 --- a/General/MsDelta.cs +++ b/General/MsDelta.cs @@ -1,8 +1,3 @@ -using System; -using System.ComponentModel; -using System.IO; -using System.Runtime.InteropServices; - namespace MeloongCore; /// diff --git a/General/OneOf.cs b/General/OneOf.cs index 3a2950e..f695d6d 100644 --- a/General/OneOf.cs +++ b/General/OneOf.cs @@ -1,6 +1,4 @@ -using System; - -namespace MeloongCore; +namespace MeloongCore; public readonly struct OneOf { private readonly int _index; diff --git a/MeloongCore.csproj b/MeloongCore.csproj index 872def8..68800d7 100644 --- a/MeloongCore.csproj +++ b/MeloongCore.csproj @@ -1,25 +1,38 @@  - - net462 - Library - True - bin\ - false - false - Debug;Release;Snapshot - true - 13.0 - + + net462 + Library + True + bin\ + false + false + Debug;Release;Snapshot + true + 13.0 + - - $(DefineConstants);SNAPSHOT - + + + + + + + + + + + + - + + $(DefineConstants);SNAPSHOT + - - True - + + + + True + diff --git a/Utils/DirectoryUtils.cs b/Utils/DirectoryUtils.cs index b107abc..9731994 100644 --- a/Utils/DirectoryUtils.cs +++ b/Utils/DirectoryUtils.cs @@ -1,12 +1,4 @@ -using MeloongCore.Extensions; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MeloongCore; +namespace MeloongCore; public static class DirectoryUtils { /// diff --git a/Utils/MathUtils.cs b/Utils/MathUtils.cs index 6d23528..d6c4e3d 100644 --- a/Utils/MathUtils.cs +++ b/Utils/MathUtils.cs @@ -1,10 +1,6 @@ -using MeloongCore.Extensions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -namespace MeloongCore; +using System.Numerics; +namespace MeloongCore; public static class MathUtils { #region 进制转换 @@ -62,7 +58,7 @@ public static class MathUtils { // 负数的结束处理与返回 if (isNegative) results.Add('-'); results.Reverse(); - return new string(results.ToArray()); + return new([..results]); } #endregion diff --git a/Utils/PathUtils.cs b/Utils/PathUtils.cs index cca0444..9d211a4 100644 --- a/Utils/PathUtils.cs +++ b/Utils/PathUtils.cs @@ -1,9 +1,4 @@ -using MeloongCore.Extensions; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -namespace MeloongCore; - +namespace MeloongCore; public static class PathUtils { ///