diff --git a/src/WeihanLi.Common/Extensions/CoreExtension.cs b/src/WeihanLi.Common/Extensions/CoreExtension.cs index a4ce2655..0d2f0080 100644 --- a/src/WeihanLi.Common/Extensions/CoreExtension.cs +++ b/src/WeihanLi.Common/Extensions/CoreExtension.cs @@ -2212,7 +2212,7 @@ public static string Concatenate(this IEnumerable source, Func /// The @this to act on. /// The value. /// true if the value is in the string, false if not. - public static bool Contains(this string @this, string value) => Guard.NotNull(@this, nameof(@this)).IndexOf(value, StringComparison.Ordinal) != -1; + public static bool Contains(this string @this, string value) => Guard.NotNull(@this).IndexOf(value, StringComparison.Ordinal) != -1; /// /// A string extension method that query if this object contains the given value. @@ -2221,7 +2221,7 @@ public static string Concatenate(this IEnumerable source, Func /// The value. /// Type of the comparison. /// true if the value is in the string, false if not. - public static bool Contains(this string @this, string value, StringComparison comparisonType) => Guard.NotNull(@this, nameof(@this)).IndexOf(value, comparisonType) != -1; + public static bool Contains(this string @this, string value, StringComparison comparisonType) => Guard.NotNull(@this).IndexOf(value, comparisonType) != -1; /// /// A string extension method that extracts this object. @@ -2229,7 +2229,7 @@ public static string Concatenate(this IEnumerable source, Func /// The @this to act on. /// The predicate. /// A string. - public static string Extract(this string @this, Func predicate) => new(Guard.NotNull(@this, nameof(@this)).ToCharArray().Where(predicate).ToArray()); + public static string Extract(this string @this, Func predicate) => new(Guard.NotNull(@this).ToCharArray().Where(predicate).ToArray()); /// /// A string extension method that removes the letter. @@ -2237,7 +2237,7 @@ public static string Concatenate(this IEnumerable source, Func /// The @this to act on. /// The predicate. /// A string. - public static string RemoveWhere(this string @this, Func predicate) => new(Guard.NotNull(@this, nameof(@this)).ToCharArray().Where(x => !predicate(x)).ToArray()); + public static string RemoveWhere(this string @this, Func predicate) => new(Guard.NotNull(@this).ToCharArray().Where(x => !predicate(x)).ToArray()); /// /// Replaces the format item in a specified String with the text equivalent of the value of a corresponding @@ -2249,17 +2249,17 @@ public static string Concatenate(this IEnumerable source, Func /// A copy of format in which the format items have been replaced by the String equivalent of the corresponding /// instances of Object in args. /// - public static string FormatWith(this string @this, params object[] values) => string.Format(Guard.NotNull(@this, nameof(@this)), values); + public static string FormatWith(this string @this, params object?[] values) => string.Format(Guard.NotNull(@this), values); /// - /// A string extension method that query if '@this' satisfy the specified pattern. + /// A string extension method that query if '@this' satisfies the specified pattern. /// /// The @this to act on. - /// The pattern to use. Use '*' as wildcard string. - /// true if '@this' satisfy the specified pattern, false if not. + /// The pattern to use. Use '*' as a wildcard string. + /// true if '@this' satisfies the specified pattern, false if not. public static bool IsLike(this string @this, string pattern) { - // Turn the pattern into regex pattern, and match the whole string with ^$ + // Turn the pattern into a regex pattern, and match the whole string with ^$ var regexPattern = "^" + Regex.Escape(pattern) + "$"; // Escape special character ?, #, *, [], and [!] @@ -2270,7 +2270,7 @@ public static bool IsLike(this string @this, string pattern) .Replace(@"\*", ".*") .Replace(@"\#", @"\d"); - return Regex.IsMatch(Guard.NotNull(@this, nameof(@this)), regexPattern); + return Regex.IsMatch(Guard.NotNull(@this), regexPattern); } /// @@ -2313,7 +2313,7 @@ public static string SafeSubstring(this string str, int startIndex, int length) /// substring public static string Sub(this string @this, int startIndex) { - Guard.NotNull(@this, nameof(@this)); + Guard.NotNull(@this); if (startIndex >= 0) { return @this.SafeSubstring(startIndex); @@ -2333,7 +2333,7 @@ public static string Sub(this string @this, int startIndex) /// The repeated string. public static string Repeat(this string @this, int repeatCount) { - Guard.NotNull(@this, nameof(@this)); + Guard.NotNull(@this); if (@this.Length == 1) { return new string(@this[0], repeatCount); @@ -2378,14 +2378,14 @@ public static string Reverse(this string? @this) /// /// An array whose elements contain the substrings in this string that are delimited by the separator. /// - public static string[] Split(this string @this, string separator, StringSplitOptions option = StringSplitOptions.None) => Guard.NotNull(@this, nameof(@this)).Split(new[] { separator }, option); + public static string[] Split(this string @this, string separator, StringSplitOptions option = StringSplitOptions.None) => Guard.NotNull(@this).Split(new[] { separator }, option); /// /// A string extension method that converts the @this to a byte array. /// /// The @this to act on. /// @this as a byte[]. - public static byte[] ToByteArray(this string @this) => Encoding.UTF8.GetBytes(Guard.NotNull(@this, nameof(@this))); + public static byte[] ToByteArray(this string @this) => Encoding.UTF8.GetBytes(Guard.NotNull(@this)); /// /// A string extension method that converts the @this to a byte array. @@ -2393,7 +2393,7 @@ public static string Reverse(this string? @this) /// The @this to act on. /// encoding /// @this as a byte[]. - public static byte[] ToByteArray(this string @this, Encoding encoding) => encoding.GetBytes(Guard.NotNull(@this, nameof(@this))); + public static byte[] ToByteArray(this string @this, Encoding encoding) => encoding.GetBytes(Guard.NotNull(@this)); public static byte[] GetBytes(this string str) => Guard.NotNull(str, nameof(str)).GetBytes(null); @@ -2405,14 +2405,14 @@ public static string Reverse(this string? @this) /// Generic type parameter. /// The @this to act on. /// @this as a T. - public static T ToEnum(this string @this) => (T)Enum.Parse(typeof(T), Guard.NotNull(@this, nameof(@this))); + public static T ToEnum(this string @this) => (T)Enum.Parse(typeof(T), Guard.NotNull(@this)); /// /// A string extension method that converts the @this to a title case. /// /// The @this to act on. /// @this as a string. - public static string ToTitleCase(this string @this) => new CultureInfo("en-US").TextInfo.ToTitleCase(Guard.NotNull(@this, nameof(@this))); + public static string ToTitleCase(this string @this) => new CultureInfo("en-US").TextInfo.ToTitleCase(Guard.NotNull(@this)); /// /// A string extension method that converts the @this to a title case. @@ -2420,7 +2420,7 @@ public static string Reverse(this string? @this) /// The @this to act on. /// Information describing the culture. /// @this as a string. - public static string ToTitleCase(this string @this, CultureInfo cultureInfo) => cultureInfo.TextInfo.ToTitleCase(Guard.NotNull(@this, nameof(@this))); + public static string ToTitleCase(this string @this, CultureInfo cultureInfo) => cultureInfo.TextInfo.ToTitleCase(Guard.NotNull(@this)); /// /// A string extension method that truncates. @@ -2428,7 +2428,7 @@ public static string Reverse(this string? @this) /// The @this to act on. /// The maximum length. /// A string. - public static string Truncate(this string @this, int maxLength) => Guard.NotNull(@this, nameof(@this)).Truncate(maxLength, "..."); + public static string Truncate(this string @this, int maxLength) => Guard.NotNull(@this).Truncate(maxLength, "..."); /// /// A string extension method that truncates.