mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-04-18 23:22:51 +08:00
bugfix
This commit is contained in:
parent
f3d0f98970
commit
52b3170e10
13
src/Constant/Regexes.cs
Normal file
13
src/Constant/Regexes.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace NSExt.Constant;
|
||||
#pragma warning disable SYSLIB1045
|
||||
|
||||
// 使用 RegexGenerator 新特性会生成重复key值的xmlcomment导致出错
|
||||
internal static class Regexes
|
||||
{
|
||||
public static readonly Regex RegexHtmlTag = new("<[^>]*>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static readonly Regex RegexMobile
|
||||
= new("^(\\d{3})\\d{4}(\\d{4})$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static readonly Regex RegexUpLetter = new("([A-Z])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
}
|
@ -15,14 +15,12 @@ public static class JsonSerializerOptionsExtensions
|
||||
public static JsonSerializerOptions NewJsonSerializerOptions(this JsonSerializerOptions _)
|
||||
{
|
||||
return new JsonSerializerOptions {
|
||||
ReadCommentHandling = JsonCommentHandling.Skip
|
||||
, AllowTrailingCommas = true
|
||||
, DictionaryKeyPolicy = JsonNamingPolicy.CamelCase
|
||||
, PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
, NumberHandling
|
||||
= JsonNumberHandling.AllowReadingFromString |
|
||||
JsonNumberHandling.WriteAsString
|
||||
ReadCommentHandling = JsonCommentHandling.Skip
|
||||
, AllowTrailingCommas = true
|
||||
, DictionaryKeyPolicy = JsonNamingPolicy.CamelCase
|
||||
, PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
, NumberHandling = JsonNumberHandling.AllowReadingFromString
|
||||
, PropertyNameCaseInsensitive = true
|
||||
};
|
||||
}
|
||||
|
@ -4,13 +4,14 @@
|
||||
#pragma warning disable CA1720
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
using NSExt.Constant;
|
||||
|
||||
namespace NSExt.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// StringExtensions
|
||||
/// </summary>
|
||||
public static partial class StringExtensions
|
||||
public static class StringExtensions
|
||||
{
|
||||
private static readonly JsonSerializerOptions _defaultJsonSerializerOptions
|
||||
= default(JsonSerializerOptions).NewJsonSerializerOptions();
|
||||
@ -369,7 +370,7 @@ public static partial class StringExtensions
|
||||
/// <returns>掩码后的手机号</returns>
|
||||
public static string MaskMobile(this string me)
|
||||
{
|
||||
return MyRegex().Replace(me, "$1****$2");
|
||||
return Regexes.RegexMobile.Replace(me, "$1****$2");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -444,7 +445,7 @@ public static partial class StringExtensions
|
||||
/// <returns>处理之后的字符串</returns>
|
||||
public static string RemoveHtmlTag(this string me)
|
||||
{
|
||||
return MyRegex1().Replace(me, string.Empty);
|
||||
return Regexes.RegexHtmlTag.Replace(me, string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -473,7 +474,7 @@ public static partial class StringExtensions
|
||||
/// </summary>
|
||||
public static string Snakecase(this string me)
|
||||
{
|
||||
return MyRegex2().Replace(me, "-$1").ToLower(CultureInfo.InvariantCulture).TrimStart('-');
|
||||
return Regexes.RegexUpLetter.Replace(me, "-$1").ToLower(CultureInfo.InvariantCulture).TrimStart('-');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -541,13 +542,4 @@ public static partial class StringExtensions
|
||||
.Replace("-", string.Empty)
|
||||
.ToLower(CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
[GeneratedRegex("^(\\d{3})\\d{4}(\\d{4})$")]
|
||||
private static partial Regex MyRegex();
|
||||
|
||||
[GeneratedRegex("<[^>]*>")]
|
||||
private static partial Regex MyRegex1();
|
||||
|
||||
[GeneratedRegex("([A-Z])")]
|
||||
private static partial Regex MyRegex2();
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net7.0</TargetFrameworks>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="MinVer" Version="4.3.0-beta.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="../CodeQuality.props"/>
|
||||
<Import Project="../CodeQuality.props" />
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user