Compare commits

..

No commits in common. "13f8ae51c2e4cfd527725b9420a30919a37d55e2" and "485e7a0ead14716270a404b20b3bc5ec9fdc1638" have entirely different histories.

5 changed files with 54 additions and 45 deletions

View File

@ -1,19 +0,0 @@
namespace NSExt.Constant;
#pragma warning disable SYSLIB1045
// 使用 RegexGenerator 新特性会生成重复key值的xmlcomment导致出错
internal static class Regexes
{
public static readonly Regex RegexBacksLantUnicode
= new("\\\\u([a-fA-F0-9]{4})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
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 RegexPercentUnicode
= new("\\\\u([a-fA-F0-9]{4})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static readonly Regex RegexUpLetter = new("([A-Z])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
}

View File

@ -15,17 +15,29 @@ public static class DbCommandExtensions
//应逆向替换,否则由于 多个表的过滤器问题导致替换不完整 如 @TenantId1 @TenantId10
for (var i = me.Parameters.Count - 1; i >= 0; i--) {
#pragma warning disable IDE0072
sql = me.Parameters[i].DbType switch {
#pragma warning restore IDE0072
DbType.String or DbType.DateTime or DbType.Date or DbType.Time or DbType.DateTime2
or DbType.DateTimeOffset or DbType.Guid or DbType.VarNumeric or DbType.AnsiStringFixedLength
or DbType.AnsiString
or DbType.StringFixedLength =>
sql.Replace(me.Parameters[i].ParameterName, "'" + me.Parameters[i].Value + "'")
, DbType.Boolean => sql.Replace(//
or DbType.AnsiString or DbType.StringFixedLength => sql.Replace( //
me.Parameters[i].ParameterName, "'" + me.Parameters[i].Value + "'")
, DbType.Boolean => sql.Replace( //
me.Parameters[i].ParameterName
, Convert.ToBoolean(me.Parameters[i].Value, CultureInfo.InvariantCulture) ? "1" : "0")
, DbType.Binary => throw new NotImplementedException()
, DbType.Byte => throw new NotImplementedException()
, DbType.Currency => throw new NotImplementedException()
, DbType.Decimal => throw new NotImplementedException()
, DbType.Double => throw new NotImplementedException()
, DbType.Int16 => throw new NotImplementedException()
, DbType.Int32 => throw new NotImplementedException()
, DbType.Int64 => throw new NotImplementedException()
, DbType.Object => throw new NotImplementedException()
, DbType.SByte => throw new NotImplementedException()
, DbType.Single => throw new NotImplementedException()
, DbType.UInt16 => throw new NotImplementedException()
, DbType.UInt32 => throw new NotImplementedException()
, DbType.UInt64 => throw new NotImplementedException()
, DbType.Xml => throw new NotImplementedException()
, _ => sql.Replace(me.Parameters[i].ParameterName, me.Parameters[i].Value?.ToString())
};
}

View File

@ -20,7 +20,9 @@ public static class JsonSerializerOptionsExtensions
, DictionaryKeyPolicy = JsonNamingPolicy.CamelCase
, PropertyNamingPolicy = JsonNamingPolicy.CamelCase
, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
, NumberHandling = JsonNumberHandling.AllowReadingFromString
, NumberHandling
= JsonNumberHandling.AllowReadingFromString |
JsonNumberHandling.WriteAsString
, PropertyNameCaseInsensitive = true
};
}

View File

@ -4,14 +4,13 @@
#pragma warning disable CA1720
using System.Security.Cryptography;
using System.Text.Json;
using NSExt.Constant;
namespace NSExt.Extensions;
/// <summary>
/// StringExtensions
/// </summary>
public static class StringExtensions
public static partial class StringExtensions
{
private static readonly JsonSerializerOptions _defaultJsonSerializerOptions
= default(JsonSerializerOptions).NewJsonSerializerOptions();
@ -370,7 +369,7 @@ public static class StringExtensions
/// <returns>掩码后的手机号</returns>
public static string MaskMobile(this string me)
{
return Regexes.RegexMobile.Replace(me, "$1****$2");
return RegexMobile().Replace(me, "$1****$2");
}
/// <summary>
@ -445,7 +444,7 @@ public static class StringExtensions
/// <returns>处理之后的字符串</returns>
public static string RemoveHtmlTag(this string me)
{
return Regexes.RegexHtmlTag.Replace(me, string.Empty);
return RegexHtmlTag().Replace(me, string.Empty);
}
/// <summary>
@ -474,7 +473,7 @@ public static class StringExtensions
/// </summary>
public static string Snakecase(this string me)
{
return Regexes.RegexUpLetter.Replace(me, "-$1").ToLower(CultureInfo.InvariantCulture).TrimStart('-');
return RegexUpperCaseLetter().Replace(me, "-$1").ToLower(CultureInfo.InvariantCulture).TrimStart('-');
}
/// <summary>
@ -514,8 +513,8 @@ public static class StringExtensions
public static string UnicodeDe(this string me)
{
const string replacement = "&#x$1;";
return me.Contains(@"\u") ? Regexes.RegexBacksLantUnicode.Replace(me, replacement).HtmlDe() :
me.Contains(@"%u") ? Regexes.RegexPercentUnicode.Replace(me, replacement).HtmlDe() : me.HtmlDe();
return me.Contains(@"\u") ? RegexBacksLantUnicode().Replace(me, replacement).HtmlDe() :
me.Contains(@"%u") ? RegexPercentUnicode().Replace(me, replacement).HtmlDe() : me.HtmlDe();
}
/// <summary>
@ -552,4 +551,19 @@ public static class StringExtensions
.Replace("-", string.Empty)
.ToLower(CultureInfo.CurrentCulture);
}
[GeneratedRegex("\\\\u([a-fA-F0-9]{4})")]
private static partial Regex RegexBacksLantUnicode();
[GeneratedRegex("<[^>]*>")]
private static partial Regex RegexHtmlTag();
[GeneratedRegex("^(\\d{3})\\d{4}(\\d{4})$")]
private static partial Regex RegexMobile();
[GeneratedRegex("\\\\u([a-fA-F0-9]{4})")]
private static partial Regex RegexPercentUnicode();
[GeneratedRegex("([A-Z])")]
private static partial Regex RegexUpperCaseLetter();
}

View File

@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>net7.0</TargetFrameworks>
<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>