mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-04-20 01: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 _)
|
public static JsonSerializerOptions NewJsonSerializerOptions(this JsonSerializerOptions _)
|
||||||
{
|
{
|
||||||
return new JsonSerializerOptions {
|
return new JsonSerializerOptions {
|
||||||
ReadCommentHandling = JsonCommentHandling.Skip
|
ReadCommentHandling = JsonCommentHandling.Skip
|
||||||
, AllowTrailingCommas = true
|
, AllowTrailingCommas = true
|
||||||
, DictionaryKeyPolicy = JsonNamingPolicy.CamelCase
|
, DictionaryKeyPolicy = JsonNamingPolicy.CamelCase
|
||||||
, PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
, PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||||
, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||||
, NumberHandling
|
, NumberHandling = JsonNumberHandling.AllowReadingFromString
|
||||||
= JsonNumberHandling.AllowReadingFromString |
|
|
||||||
JsonNumberHandling.WriteAsString
|
|
||||||
, PropertyNameCaseInsensitive = true
|
, PropertyNameCaseInsensitive = true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
#pragma warning disable CA1720
|
#pragma warning disable CA1720
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using NSExt.Constant;
|
||||||
|
|
||||||
namespace NSExt.Extensions;
|
namespace NSExt.Extensions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// StringExtensions
|
/// StringExtensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static partial class StringExtensions
|
public static class StringExtensions
|
||||||
{
|
{
|
||||||
private static readonly JsonSerializerOptions _defaultJsonSerializerOptions
|
private static readonly JsonSerializerOptions _defaultJsonSerializerOptions
|
||||||
= default(JsonSerializerOptions).NewJsonSerializerOptions();
|
= default(JsonSerializerOptions).NewJsonSerializerOptions();
|
||||||
@ -369,7 +370,7 @@ public static partial class StringExtensions
|
|||||||
/// <returns>掩码后的手机号</returns>
|
/// <returns>掩码后的手机号</returns>
|
||||||
public static string MaskMobile(this string me)
|
public static string MaskMobile(this string me)
|
||||||
{
|
{
|
||||||
return MyRegex().Replace(me, "$1****$2");
|
return Regexes.RegexMobile.Replace(me, "$1****$2");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -444,7 +445,7 @@ public static partial class StringExtensions
|
|||||||
/// <returns>处理之后的字符串</returns>
|
/// <returns>处理之后的字符串</returns>
|
||||||
public static string RemoveHtmlTag(this string me)
|
public static string RemoveHtmlTag(this string me)
|
||||||
{
|
{
|
||||||
return MyRegex1().Replace(me, string.Empty);
|
return Regexes.RegexHtmlTag.Replace(me, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -473,7 +474,7 @@ public static partial class StringExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string Snakecase(this string me)
|
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>
|
/// <summary>
|
||||||
@ -541,13 +542,4 @@ public static partial class StringExtensions
|
|||||||
.Replace("-", string.Empty)
|
.Replace("-", string.Empty)
|
||||||
.ToLower(CultureInfo.CurrentCulture);
|
.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">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net7.0</TargetFrameworks>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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">
|
<PackageReference Include="MinVer" Version="4.3.0-beta.1">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Import Project="../CodeQuality.props"/>
|
<Import Project="../CodeQuality.props" />
|
||||||
</Project>
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user