This commit is contained in:
nsnail 2022-09-15 15:44:11 +08:00
parent ff3915f4fc
commit 637eaab56e
8 changed files with 34 additions and 36 deletions

View File

@ -1,6 +1,4 @@
using System.Text;
namespace NSExt;
namespace NSExt;
public static class ByteExtensions
{

View File

@ -1,7 +1,4 @@
using System.Data;
using System.Data.Common;
namespace NSExt;
namespace NSExt;
public static class DbCommandExtensions
{

View File

@ -1,6 +1,4 @@
using System.ComponentModel;
namespace NSExt;
namespace NSExt;
public static class EnumExtensions
{

12
src/NSExt/GlobalUsings.cs Normal file
View File

@ -0,0 +1,12 @@
global using System.Data;
global using System.Data.Common;
global using System.Runtime.CompilerServices;
global using Microsoft.Extensions.Logging;
global using System.Globalization;
global using System.Text;
global using System.Text.RegularExpressions;
global using System.Web;
global using Newtonsoft.Json;
global using Newtonsoft.Json.Linq;
global using System.ComponentModel;
global using SshNet.Security.Cryptography;

View File

@ -1,8 +1,4 @@
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
// ReSharper disable TemplateIsNotCompileTimeConstantProblem
// ReSharper disable TemplateIsNotCompileTimeConstantProblem
namespace NSExt;
@ -29,15 +25,11 @@ public static class LoggerExtensions
public static void Error(this ILogger me,
object message,
Exception ex = null,
[CallerMemberName] string callerName = null,
[CallerFilePath] string callerFilePath = null,
[CallerLineNumber] int callerLineNumber = 0)
{
if (ex is null)
me.LogError(CallerInfoMessage(message, callerName, callerFilePath, callerLineNumber));
else
me.LogError(CallerInfoMessage(message, callerName, callerFilePath, callerLineNumber), ex);
me.LogError(CallerInfoMessage(message, callerName, callerFilePath, callerLineNumber));
}
public static void Fatal(this ILogger me,

View File

@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0-rc.1.22426.10"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2"/>
<PackageReference Include="SshNet.Security.Cryptography" Version="1.3.0"/>
</ItemGroup>

View File

@ -1,6 +1,4 @@
using Newtonsoft.Json;
namespace NSExt;
namespace NSExt;
public static class ObjectExtensions
{

View File

@ -1,13 +1,10 @@
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using MD5 = SshNet.Security.Cryptography.MD5;
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Global
using System.Security.Cryptography;
using HMACMD5 = SshNet.Security.Cryptography.HMACMD5;
using HMACSHA1 = SshNet.Security.Cryptography.HMACSHA1;
using MD5 = SshNet.Security.Cryptography.MD5;
namespace NSExt;
@ -283,7 +280,7 @@ public static class StringExtensions
/// <returns>hash摘要的16进制文本形式无连字符小写</returns>
public static string Sha1(this string me, Encoding e)
{
using var sha1 = SHA1.Create();
using var sha1 = HashAlgorithm.Create();
return BitConverter.ToString(sha1.ComputeHash(e.GetBytes(me)))
.Replace("-", string.Empty)
.ToLower(CultureInfo.CurrentCulture);
@ -438,4 +435,10 @@ public static class StringExtensions
{
return BitConverter.ToInt32(me.Split('.').Select(byte.Parse).Reverse().ToArray(), 0);
}
public static bool NullOrWhiteSpace(this string me)
{
return string.IsNullOrWhiteSpace(me);
}
}