This commit is contained in:
nsnail 2022-09-14 18:43:29 +08:00
parent d744df3044
commit ff3915f4fc
13 changed files with 41 additions and 96 deletions

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: ByteExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
using System.Text;
using System.Text;
namespace NSExt;

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: DateTimeExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Global
namespace NSExt;

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: DbCommandExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 08/06/2022 19:48
using System.Data;
using System.Data;
using System.Data.Common;
namespace NSExt;

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: DecimalExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
namespace NSExt;
namespace NSExt;
public static class DecimalExtensions
{

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: EnumExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
using System.ComponentModel;
using System.ComponentModel;
namespace NSExt;

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: EnumerableExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
namespace NSExt;
namespace NSExt;
public static class EnumerableExtensions
{

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: GenericExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
namespace NSExt;
namespace NSExt;
public static class GenericExtensions
{

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: IntExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
namespace NSExt;
namespace NSExt;
public static class IntExtensions
{

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: LoggerExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
// ReSharper disable TemplateIsNotCompileTimeConstantProblem

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: LongExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
namespace NSExt;
namespace NSExt;
public static class LongExtensions
{

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: ObjectExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
using Newtonsoft.Json;
using Newtonsoft.Json;
namespace NSExt;

View File

@ -1,17 +1,10 @@
// @program: NSExt
// @file: StringExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
using System.Globalization;
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 HMACMD5 = System.Security.Cryptography.HMACMD5;
using MD5 = SshNet.Security.Cryptography.MD5;
// ReSharper disable UnusedMember.Global
@ -82,6 +75,18 @@ public static class StringExtensions
return System.DateTime.Parse(me, CultureInfo.CurrentCulture);
}
/// <summary>
/// 将字符串转换成日期对象
/// </summary>
/// <param name="me">待转换字符串</param>
/// <param name="format">日期格式</param>
/// <returns>转换后的日期对象</returns>
public static DateTime DateTimeExact(this string me, string format)
{
return System.DateTime.ParseExact(me, format, CultureInfo.CurrentCulture);
}
/// <summary>
/// 将字符串转换成日期对象
/// </summary>
@ -93,6 +98,20 @@ public static class StringExtensions
return !System.DateTime.TryParse(me, out var ret) ? def : ret;
}
/// <summary>
/// 将字符串转换成日期对象
/// </summary>
/// <param name="me">待转换字符串</param>
/// <param name="format">日期格式</param>
/// <param name="def">转换失败时返回的日期对象</param>
/// <returns>转换后的日期对象</returns>
public static DateTime DateTimeExactTry(this string me, string format, DateTime def)
{
return !System.DateTime.TryParseExact(me, format, CultureInfo.CurrentCulture, DateTimeStyles.None, out var ret)
? def
: ret;
}
/// <summary>
/// string to decimal
/// </summary>
@ -123,7 +142,7 @@ public static class StringExtensions
/// <returns></returns>
public static T Enum<T>(this string name) where T : Enum
{
return (T)System.Enum.Parse(typeof(T), name);
return (T)System.Enum.Parse(typeof(T), name, true);
}
@ -271,7 +290,7 @@ public static class StringExtensions
}
/// <summary>
/// 对一个字符串进行sha1 hash运算
/// 对一个字符串进行sha1 hash运算
/// </summary>
/// <param name="me">对一个字符串进行sha1 hash运算</param>
/// <param name="secret">密钥</param>
@ -301,8 +320,6 @@ public static class StringExtensions
.ToLower(CultureInfo.CurrentCulture);
}
/// <summary>
/// MD5 hmac编码

View File

@ -1,10 +1,4 @@
// @program: NSExt
// @file: UriExtensions.cs
// @author: tao ke
// @mailto: taokeu@gmail.com
// @created: 07/26/2022 21:57
namespace NSExt;
namespace NSExt;
public static class UriExtensions
{