Browse Source

精简语法

懒得勤快 5 years ago
parent
commit
d52f23a4d3

+ 10 - 8
Masuit.Tools.Abstractions/Extensions/BaseType/StringExtensions.cs

@@ -156,12 +156,12 @@ namespace Masuit.Tools
             string masks = mask.ToString().PadLeft(4, mask);
             return s.Length switch
             {
-                _ when s.Length >= 11 => Regex.Replace(s, "(.{3}).*(.{4})", $"$1{masks}$2"),
-                _ when s.Length == 10 => Regex.Replace(s, "(.{3}).*(.{3})", $"$1{masks}$2"),
-                _ when s.Length == 9 => Regex.Replace(s, "(.{2}).*(.{3})", $"$1{masks}$2"),
-                _ when s.Length == 8 => Regex.Replace(s, "(.{2}).*(.{2})", $"$1{masks}$2"),
-                _ when s.Length == 7 => Regex.Replace(s, "(.{1}).*(.{2})", $"$1{masks}$2"),
-                _ when s.Length == 6 => Regex.Replace(s, "(.{1}).*(.{1})", $"$1{masks}$2"),
+                >= 11 => Regex.Replace(s, "(.{3}).*(.{4})", $"$1{masks}$2"),
+                10 => Regex.Replace(s, "(.{3}).*(.{3})", $"$1{masks}$2"),
+                9 => Regex.Replace(s, "(.{2}).*(.{3})", $"$1{masks}$2"),
+                8 => Regex.Replace(s, "(.{2}).*(.{2})", $"$1{masks}$2"),
+                7 => Regex.Replace(s, "(.{1}).*(.{2})", $"$1{masks}$2"),
+                6 => Regex.Replace(s, "(.{1}).*(.{1})", $"$1{masks}$2"),
                 _ => Regex.Replace(s, "(.{1}).*", $"$1{masks}")
             };
         }
@@ -201,7 +201,9 @@ namespace Masuit.Tools
         /// <returns></returns>
         public static string MaskEmail(this string s, char mask = '*')
         {
-            return !MatchEmail(s).isMatch ? s : s.Replace(s.Substring(0, s.LastIndexOf("@")), Mask(s.Substring(0, s.LastIndexOf("@")), mask));
+            var index = s.LastIndexOf("@");
+            var oldValue = s.Substring(0, index);
+            return !MatchEmail(s).isMatch ? s : s.Replace(oldValue, Mask(oldValue, mask));
         }
 
         #endregion Email
@@ -467,7 +469,7 @@ namespace Masuit.Tools
         /// <returns></returns>
         public static byte[] ToByteArray(this string @this)
         {
-            return Activator.CreateInstance<ASCIIEncoding>().GetBytes(@this);
+            return Encoding.ASCII.GetBytes(@this);
         }
 
         #region Crc32

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

@@ -4,7 +4,7 @@
 
   <PropertyGroup>
     <TargetFrameworks>netstandard2.0;netstandard2.1;net461;net5</TargetFrameworks>
-    <LangVersion>8.0</LangVersion>
+    <LangVersion>9.0</LangVersion>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <CodeAnalysisRuleSet />
     <Version>2.4.0</Version>

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

@@ -17,7 +17,7 @@
         <PackageLicenseUrl>https://github.com/ldqk/Masuit.Tools/blob/master/LICENSE</PackageLicenseUrl>
         <Product>Masuit.Tools.Core</Product>
         <PackageId>Masuit.Tools.Core</PackageId>
-        <LangVersion>8.0</LangVersion>
+        <LangVersion>preview</LangVersion>
         <UserSecretsId>830c282f-f7c1-42be-8651-4cd06ac8e73f</UserSecretsId>
         <RepositoryType>Github</RepositoryType>
         <GeneratePackageOnBuild>True</GeneratePackageOnBuild>

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

@@ -28,7 +28,7 @@
     <DocumentationFile>bin\Debug\Masuit.Tools.XML</DocumentationFile>
     <NoWarn>1591</NoWarn>
     <CodeAnalysisRuleSet />
-    <LangVersion>8.0</LangVersion>
+    <LangVersion>9.0</LangVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>