This commit is contained in:
nsnail 2022-09-22 11:44:40 +08:00
parent 847012041a
commit 6fdf879be0
16 changed files with 50 additions and 37 deletions

View File

@ -1,4 +1,4 @@
namespace NSExt;
namespace NSExt.Extensions;
public static class ByteExtensions
{

View File

@ -1,6 +1,6 @@
// ReSharper disable UnusedMember.Global
namespace NSExt;
namespace NSExt.Extensions;
public static class DateTimeExtensions
{

View File

@ -1,4 +1,4 @@
namespace NSExt;
namespace NSExt.Extensions;
public static class DbCommandExtensions
{

View File

@ -1,4 +1,4 @@
namespace NSExt;
namespace NSExt.Extensions;
public static class DecimalExtensions
{

View File

@ -1,4 +1,4 @@
namespace NSExt;
namespace NSExt.Extensions;
public static class EnumExtensions
{

View File

@ -1,4 +1,4 @@
namespace NSExt;
namespace NSExt.Extensions;
public static class EnumerableExtensions
{

View File

@ -1,4 +1,4 @@
namespace NSExt;
namespace NSExt.Extensions;
public static class GenericExtensions
{

View File

@ -1,4 +1,4 @@
namespace NSExt;
namespace NSExt.Extensions;
public static class IntExtensions
{

View File

@ -1,6 +1,6 @@
// ReSharper disable TemplateIsNotCompileTimeConstantProblem
namespace NSExt;
namespace NSExt.Extensions;
public static class LoggerExtensions
{

View File

@ -1,4 +1,4 @@
namespace NSExt;
namespace NSExt.Extensions;
public static class LongExtensions
{

View File

@ -0,0 +1,33 @@
using Newtonsoft.Json.Serialization;
namespace NSExt.Extensions;
public static class ObjectExtensions
{
/// <summary>
/// 将一个对象序列化成json文本
/// </summary>
/// <param name="me">指定对象</param>
/// <param name="format">是否格式化</param>
/// <returns>json文本</returns>
public static string Json(this object me, bool format = false)
{
return JsonConvert.SerializeObject(me, format ? Formatting.Indented : Formatting.None);
}
/// <summary>
/// 将一个对象序列化成json文本小驼峰属性名
/// </summary>
/// <param name="me">指定对象</param>
/// <param name="format">是否格式化</param>
/// <returns>json文本</returns>
public static string JsonCamelCase(this object me, bool format = false)
{
return JsonConvert.SerializeObject(me,
new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Formatting = format ? Formatting.Indented : Formatting.None
});
}
}

View File

@ -2,11 +2,8 @@
using System.Security.Cryptography;
using HMACMD5 = SshNet.Security.Cryptography.HMACMD5;
using HMACSHA1 = SshNet.Security.Cryptography.HMACSHA1;
using MD5 = SshNet.Security.Cryptography.MD5;
namespace NSExt;
namespace NSExt.Extensions;
public static class StringExtensions
{
@ -280,7 +277,7 @@ public static class StringExtensions
/// <returns>hash摘要的16进制文本形式无连字符小写</returns>
public static string Sha1(this string me, Encoding e)
{
using var sha1 = HashAlgorithm.Create();
using var sha1 = SHA1.Create();
return BitConverter.ToString(sha1.ComputeHash(e.GetBytes(me)))
.Replace("-", string.Empty)
.ToLower(CultureInfo.CurrentCulture);
@ -311,7 +308,7 @@ public static class StringExtensions
/// <returns>hash摘要的16进制文本形式无连字符小写</returns>
public static string Md5(this string me, Encoding e)
{
using var md5 = new MD5();
using var md5 = MD5.Create();
return BitConverter.ToString(md5.ComputeHash(e.GetBytes(me)))
.Replace("-", string.Empty)
.ToLower(CultureInfo.CurrentCulture);

View File

@ -1,4 +1,4 @@
namespace NSExt;
namespace NSExt.Extensions;
public static class UriExtensions
{

View File

@ -9,4 +9,3 @@ global using System.Web;
global using Newtonsoft.Json;
global using Newtonsoft.Json.Linq;
global using System.ComponentModel;
global using SshNet.Security.Cryptography;

View File

@ -15,7 +15,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" />
<PackageReference Include="SshNet.Security.Cryptography" Version="1.3.0"/>
</ItemGroup>

View File

@ -1,15 +0,0 @@
namespace NSExt;
public static class ObjectExtensions
{
/// <summary>
/// 将一个对象序列化成json文本
/// </summary>
/// <param name="me">指定对象</param>
/// <param name="format">是否格式化</param>
/// <returns>json文本</returns>
public static string Json(this object me, bool format = false)
{
return JsonConvert.SerializeObject(me, format ? Formatting.Indented : Formatting.None);
}
}