From 8be57eb109336debc00f19f669ad6e8392e675c2 Mon Sep 17 00:00:00 2001 From: wayd13140659949 <13140659949@163.com> Date: Thu, 30 Jun 2022 10:46:10 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E5=91=BD=E4=BB=A4.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\345\217\221\345\270\203\345\221\275\344\273\244.txt" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/\345\217\221\345\270\203/\345\217\221\345\270\203\345\221\275\344\273\244.txt" "b/\345\217\221\345\270\203/\345\217\221\345\270\203\345\221\275\344\273\244.txt" index 40c09e3..ca3c30f 100644 --- "a/\345\217\221\345\270\203/\345\217\221\345\270\203\345\221\275\344\273\244.txt" +++ "b/\345\217\221\345\270\203/\345\217\221\345\270\203\345\221\275\344\273\244.txt" @@ -1,3 +1,3 @@ -./nuget.exe push SageTools.0.0.4.nupkg oy2eefk5urope2lduvsqy7add6xv6ftufjgyhfsti6l4cq -Source https://api.nuget.org/v3/index.json +./nuget.exe push SageTools.0.0.4.nupkg ApiKey -Source https://api.nuget.org/v3/index.json -dotnet nuget push SageTools.0.0.4.nupkg oy2eefk5urope2lduvsqy7add6xv6ftufjgyhfsti6l4cq -s https://api.nuget.org/v3/index.json \ No newline at end of file +dotnet nuget push SageTools.0.0.4.nupkg ApiKey -s https://api.nuget.org/v3/index.json \ No newline at end of file From f23e5edecb2eb577d4494a5da77bd0bbb64587fc Mon Sep 17 00:00:00 2001 From: wayd13140659949 <13140659949@163.com> Date: Thu, 30 Jun 2022 02:46:36 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=20readme.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SageTools/readme.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 SageTools/readme.md diff --git a/SageTools/readme.md b/SageTools/readme.md deleted file mode 100644 index 93237b4..0000000 --- a/SageTools/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -oy2eefk5urope2lduvsqy7add6xv6ftufjgyhfsti6l4cq - -2022年1月13日签发,有效期一年 \ No newline at end of file From ee6f0f48a279c27c3cd098ffba34419a7d4ab5a0 Mon Sep 17 00:00:00 2001 From: LiuDanK <13140659949@163.com> Date: Thu, 30 Jun 2022 10:49:27 +0800 Subject: [PATCH 3/5] add readme.md --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f43aa58 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +[toc] + +# SageTools + +#### 介绍 + +SageTools 一个简单的常用工具类和拓展方法包 + + +#### 安装教程 + + +#### 使用说明 + + + +#### 参与贡献 + + +#### 计划中的功能 + + + +#### 详细功能 + + From 49ffae5f65bba8d52d0dab6cd5756dad9461087f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=89=E4=BA=9E=E5=9D=A4?= <13140659949@163.com> Date: Mon, 31 Oct 2022 13:58:17 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SageTools/Extension/Collection.cs | 29 +++++++++++++++-- SageTools/Extension/DateTime.cs | 10 ++++++ SageTools/Extension/Number.cs | 18 +---------- SageTools/Extension/String.cs | 53 +++++++++++++++++++++++++------ 4 files changed, 82 insertions(+), 28 deletions(-) diff --git a/SageTools/Extension/Collection.cs b/SageTools/Extension/Collection.cs index f3aadff..d60c9e4 100644 --- a/SageTools/Extension/Collection.cs +++ b/SageTools/Extension/Collection.cs @@ -95,11 +95,11 @@ public static void PagingToOperate(this ICollection list, Action源数据集合 /// 要进行的操作 /// 每页大小 - public static void PagingToOperate(this ICollection list, Action,int> action, int pageSize = 1000) + public static void PagingToOperate(this ICollection list, Action, int> action, int pageSize = 1000) { if (list.IsNullOrEmpty() || list.Count <= pageSize) { - action(list,1); + action(list, 1); } else { @@ -111,5 +111,30 @@ public static void PagingToOperate(this ICollection list, Action + /// 页码转偏移量;拒绝大量 pageIndex-1 + /// + /// + /// + /// + public static int PageIndexToOffset(this int pageIndex, int pageSize) + { + return (pageIndex - 1) * pageSize; + } + + /// + /// 计算分页页数 + /// + /// 总条数 + /// 页大小 + /// + public static int ToPageCount(this int totalCount, int pageSize) + { + if (totalCount == 0 || pageSize == 0) return 0; + if (totalCount <= pageSize) return 1; + if (pageSize == 1) return totalCount; + return (int)Math.Ceiling(1D * totalCount / pageSize); + } } } \ No newline at end of file diff --git a/SageTools/Extension/DateTime.cs b/SageTools/Extension/DateTime.cs index b9f0d60..28dcd5d 100644 --- a/SageTools/Extension/DateTime.cs +++ b/SageTools/Extension/DateTime.cs @@ -175,5 +175,15 @@ public static long ToTimeStamp(this DateTime @this) return (long)(@this - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; } + /// + /// 时间戳转时间(秒) + /// + /// 时间戳(秒) + /// + public static DateTime ToDateTime(this long timeStamp) + { + return new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(timeStamp); + } + } } \ No newline at end of file diff --git a/SageTools/Extension/Number.cs b/SageTools/Extension/Number.cs index 0e4495f..028e986 100644 --- a/SageTools/Extension/Number.cs +++ b/SageTools/Extension/Number.cs @@ -105,23 +105,7 @@ public static bool ToBool(this int num) return num == 1; } - /// - /// 计算分页页数 - /// - /// 总条数 - /// 页大小 - /// - public static int ToPageCount(this int totalCount,int pageSize) - { - if(totalCount==0 || pageSize==0)return 0; - if (totalCount <= pageSize) return 1; - if (pageSize == 1) return totalCount; - return (int)Math.Ceiling(1D * totalCount / pageSize); - } - public static DateTime ToDateTime(this long timeStamp) - { - return new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(timeStamp); - } + } } \ No newline at end of file diff --git a/SageTools/Extension/String.cs b/SageTools/Extension/String.cs index 5212dd1..6105c07 100644 --- a/SageTools/Extension/String.cs +++ b/SageTools/Extension/String.cs @@ -5,13 +5,10 @@ using System.IO; using System.Linq; using System.Net; -using System.Reflection; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Web; -using System.Xml.Linq; -using System.Xml; namespace SageTools.Extension { @@ -149,74 +146,108 @@ public static SqlDbType SqlTypeNameToSqlDbType(this string @this) { case "bigint": return SqlDbType.BigInt; + case "binary": return SqlDbType.Binary; + case "bit": return SqlDbType.Bit; + case "char": return SqlDbType.Char; + case "date": return SqlDbType.Date; + case "datetime": return SqlDbType.DateTime; + case "datetime2": return SqlDbType.DateTime2; + case "datetimeoffset": return SqlDbType.DateTimeOffset; + case "decimal": return SqlDbType.Decimal; + case "float": return SqlDbType.Float; + case "geography": return SqlDbType.Udt; + case "geometry": return SqlDbType.Udt; + case "hierarchyid": return SqlDbType.Udt; + case "image": return SqlDbType.Image; + case "int": return SqlDbType.Int; + case "money": return SqlDbType.Money; + case "nchar": return SqlDbType.NChar; + case "ntext": return SqlDbType.NText; + case "numeric": return SqlDbType.Decimal; + case "nvarchar": return SqlDbType.NVarChar; + case "real": return SqlDbType.Real; + case "smalldatetime": return SqlDbType.SmallDateTime; + case "smallint": return SqlDbType.SmallInt; + case "smallmoney": return SqlDbType.SmallMoney; + case "sql_variant": return SqlDbType.Variant; + case "sysname": return SqlDbType.NVarChar; + case "text": return SqlDbType.Text; + case "time": return SqlDbType.Time; + case "timestamp": return SqlDbType.Timestamp; + case "tinyint": return SqlDbType.TinyInt; + case "uniqueidentifier": return SqlDbType.UniqueIdentifier; + case "varbinary": return SqlDbType.VarBinary; + case "varchar": return SqlDbType.VarChar; + case "xml": return SqlDbType.Xml; + default: - throw new Exception(string.Format("Unsupported Type: {0}", (object) @this)); + throw new Exception(string.Format("Unsupported Type: {0}", (object)@this)); } } @@ -359,7 +390,7 @@ public static StringBuilder AppendIf(this StringBuilder @this, Func foreach (var obj in values) { if (predicate(obj)) - @this.Append((object) obj); + @this.Append((object)obj); } return @this; @@ -393,7 +424,7 @@ public static StringBuilder AppendLineFormat(this StringBuilder @this, string fo /// public static StringBuilder AppendLineFormat(this StringBuilder @this, string format, List> args) { - @this.AppendLine(string.Format(format, (object) args)); + @this.AppendLine(string.Format(format, (object)args)); return @this; } @@ -556,6 +587,7 @@ public static string Base64UrlDecode(this string base64UrlStr) case 2: base64UrlStr += "=="; break; + case 3: base64UrlStr += "="; break; @@ -741,7 +773,7 @@ public static byte[] To0XBytes(this string str) for (int i = 0; i < str.Length; i = i + 2) { string numStr = $@"{str[i]}{str[i + 1]}"; - resBytes.Add((byte) numStr.ToInt0X()); + resBytes.Add((byte)numStr.ToInt0X()); } return resBytes.ToArray(); @@ -755,7 +787,7 @@ public static byte[] To0XBytes(this string str) /// public static byte[] ToASCIIBytes(this string str) { - return str.ToList().Select(x => (byte) x).ToArray(); + return str.ToList().Select(x => (byte)x).ToArray(); } /// @@ -795,12 +827,15 @@ public static T ToEntity(this string json) case "System.String": info?.SetValue(obj, match.Groups[1].ToString(), null); break; + case "System.Int32": info?.SetValue(obj, match.Groups[1].ToString().ToInt(), null); break; + case "System.Int64": info?.SetValue(obj, Convert.ToInt64(match.Groups[1].ToString()), null); break; + case "System.DateTime": info?.SetValue(obj, Convert.ToDateTime(match.Groups[1].ToString()), null); break; @@ -808,7 +843,7 @@ public static T ToEntity(this string json) } } - return (T) obj; + return (T)obj; } /// From c52cc07717fd4b41b7156601aa7d05be6196ee6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=89=E4=BA=9E=E5=9D=A4?= <13140659949@163.com> Date: Tue, 6 Dec 2022 14:57:18 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SageTools/Extension/DateTime.cs | 4 + SageTools/Extension/Regex.cs | 77 +++++++++++ SageTools/Extension/String.cs | 222 +++----------------------------- 3 files changed, 96 insertions(+), 207 deletions(-) create mode 100644 SageTools/Extension/Regex.cs diff --git a/SageTools/Extension/DateTime.cs b/SageTools/Extension/DateTime.cs index 28dcd5d..dcd7f58 100644 --- a/SageTools/Extension/DateTime.cs +++ b/SageTools/Extension/DateTime.cs @@ -185,5 +185,9 @@ public static DateTime ToDateTime(this long timeStamp) return new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(timeStamp); } + /// + /// 转换为日期格式 + /// + public static DateTime ToDateTime(this string @this) => Convert.ToDateTime(@this); } } \ No newline at end of file diff --git a/SageTools/Extension/Regex.cs b/SageTools/Extension/Regex.cs new file mode 100644 index 0000000..b839047 --- /dev/null +++ b/SageTools/Extension/Regex.cs @@ -0,0 +1,77 @@ +using System; +using System.Text.RegularExpressions; + +namespace SageTools.Extension +{ + public static partial class Extension + { + /// + /// Regex.IsMatch()拓展 + /// + public static bool IsMatch(this string input, string pattern) => Regex.IsMatch(input, pattern); + + /// + /// Regex.IsMatch()拓展 + /// + public static bool IsMatch(this string input, string pattern, RegexOptions options) => Regex.IsMatch(input, pattern, options); + + /// + /// 正则判断是否为数字 + /// + public static bool IsNumeric(this string @this) => !Regex.IsMatch(@this, "[^0-9]"); + + /// + /// 是否是正确的base64字符串 + /// + public static bool IsValidBase64String(this string str) => Regex.IsMatch(str, "[A-Za-z0-9\\+\\/\\=]"); + + /// + /// 是否是正确的email地址 + /// + public static bool IsValidEmail(this string obj) => + Regex.IsMatch(obj, "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"); + + /// + /// 是否是正确的ip地址 + /// + public static bool IsValidIP(this string obj) => Regex.IsMatch(obj, + "^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$"); + + /// + /// 是否是正确的手机号 + /// + public static bool IsValidMobile(string mobile) + { + if (mobile.IsNullOrEmpty()) + return false; + mobile = mobile.Trim(); + return Regex.IsMatch(mobile, "^(1[3|4|5|6|7|8|9])\\d{9}$", RegexOptions.IgnoreCase); + } + + /// + /// 是否是安全的SQL,防注入 + /// + public static bool IsValidSafeSqlString(this string str) => !Regex.IsMatch(str, "[-|;|,|\\/|\\(|\\)|\\[|\\]|\\}|\\{|%|@|\\*|!|\\']"); + + /// + /// 是否是URL + /// + public static bool IsUrl(this string strUrl) => Regex.IsMatch(strUrl, + "^(http|https)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\\:[0-9]+)*(/($|[a-zA-Z0-9\\.\\,\\?\\'\\\\\\+&%\\$#\\=~_\\-]+))*$"); + + /// + /// 是否为弱密码 + /// 注:密码必须包含数字、小写字母、大写字母和其他符号中的两种并且长度大于8 + /// + /// 密码 + /// + public static bool IsWeakPwd(this string pwd) + { + if (pwd.IsNullOrEmpty()) + throw new Exception("pwd不能为空"); + + const string pattern = "(^[0-9]+$)|(^[a-z]+$)|(^[A-Z]+$)|(^.{0,8}$)"; + return Regex.IsMatch(pwd, pattern); + } + } +} \ No newline at end of file diff --git a/SageTools/Extension/String.cs b/SageTools/Extension/String.cs index 6105c07..3844743 100644 --- a/SageTools/Extension/String.cs +++ b/SageTools/Extension/String.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Data; -using System.Globalization; using System.IO; using System.Linq; using System.Net; @@ -14,33 +13,6 @@ namespace SageTools.Extension { public static partial class Extension { - /// - /// 从字符串中截取指定长度 - /// - /// - /// 指定的长度 - /// 当指定的长度超出或小于0时,True返回整体字符串(默认),False抛出IndexOutOfRange异常 - /// - public static string SubSpecifiedLengthStr(this string str, int length, bool returnAllOrThrowWhenIndexOutOfRange = true) - { - if (str.IsNullOrEmpty()) - { - return str; - } - - if (length == 0) - { - return string.Empty; - } - - if (length < 0 || length > str.Length) - { - return returnAllOrThrowWhenIndexOutOfRange ? str : throw new IndexOutOfRangeException(); - } - - return str.Substring(length); - } - public static bool IsNullOrEmpty(this string str) { return string.IsNullOrEmpty(str); @@ -84,39 +56,34 @@ public static bool ToBool(this string str) /// /// string.Join()拓展 /// - public static string Join(this string separator, string[] value) => string.Join(separator, value); + public static string JoinWith(this string separator, string[] value) => string.Join(separator, value); /// /// string.Join()拓展 /// - public static string Join(this string separator, object[] values) => string.Join(separator, values); + public static string JoinWith(this string separator, object[] values) => string.Join(separator, values); /// /// string.Join()拓展 /// - public static string Join(this string separator, IEnumerable values) => string.Join(separator, values); + public static string JoinWith(this string separator, IEnumerable values) => string.Join(separator, values); /// /// string.Join()拓展 /// - public static string Join(this string separator, IEnumerable values) => string.Join(separator, values); + public static string JoinWith(this string separator, IEnumerable values) => string.Join(separator, values); /// /// string.Join()拓展 /// - public static string Join(this string separator, string[] value, int startIndex, int count) => string.Join(separator, value, startIndex, count); + public static string JoinWith(this string separator, string[] value, int startIndex, int count) => string.Join(separator, value, startIndex, count); /// /// string.Replace("oldValue","") /// public static string ReplaceByEmpty(this string str, params string[] values) { - foreach (var oldValue in values) - { - str = str.Replace(oldValue, ""); - } - - return str; + return values.Aggregate(str, (current, oldValue) => current.Replace(oldValue, "")); } /// @@ -314,74 +281,6 @@ public static string Cut(this string @this, int maxLength, string suffix) return @this.Substring(0, length) + suffix; } - /// - /// 进行MD5加密 - /// - /// - /// - public static string Md5(this string str) - { - byte[] hash = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(str)); - string str1 = ""; - for (int index = 0; index < hash.Length; ++index) - str1 += hash[index].ToString("x").PadLeft(2, '0'); - return str1; - } - - /// - /// Regex.IsMatch()拓展 - /// - public static bool IsMatch(this string input, string pattern) => Regex.IsMatch(input, pattern); - - /// - /// Regex.IsMatch()拓展 - /// - public static bool IsMatch(this string input, string pattern, RegexOptions options) => Regex.IsMatch(input, pattern, options); - - /// - /// 正则判断是否为数字 - /// - public static bool IsNumeric(this string @this) => !Regex.IsMatch(@this, "[^0-9]"); - - /// - /// 是否是正确的base64字符串 - /// - public static bool IsValidBase64String(this string str) => Regex.IsMatch(str, "[A-Za-z0-9\\+\\/\\=]"); - - /// - /// 是否是正确的email地址 - /// - public static bool IsValidEmail(this string obj) => - Regex.IsMatch(obj, "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"); - - /// - /// 是否是正确的ip地址 - /// - public static bool IsValidIP(this string obj) => Regex.IsMatch(obj, - "^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$"); - - /// - /// 是否是正确的手机号 - /// - public static bool IsValidMobile(string mobile) - { - if (mobile.IsNullOrEmpty()) - return false; - mobile = mobile.Trim(); - return Regex.IsMatch(mobile, "^(1[3|4|5|6|7|8|9])\\d{9}$", RegexOptions.IgnoreCase); - } - - /// - /// 是否是安全的SQL,防注入 - /// - public static bool IsValidSafeSqlString(this string str) => !Regex.IsMatch(str, "[-|;|,|\\/|\\(|\\)|\\[|\\]|\\}|\\{|%|@|\\*|!|\\']"); - - /// - /// 是否是URL - /// - public static bool IsUrl(this string strUrl) => Regex.IsMatch(strUrl, - "^(http|https)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\\:[0-9]+)*(/($|[a-zA-Z0-9\\.\\,\\?\\'\\\\\\+&%\\$#\\=~_\\-]+))*$"); - /// /// 满足条件则添加 /// @@ -448,11 +347,6 @@ public static StringBuilder AppendLineFormat(this StringBuilder @this, string fo /// public static string Right(this string @this, int length) => @this.RightSafe(length); - /// - /// 转换为日期格式 - /// - public static DateTime ToDateTime(this string @this) => Convert.ToDateTime(@this); - /// /// 转为字节数组 /// @@ -468,7 +362,7 @@ public static byte[] ToBytes_FromBase64Str(this string base64Str) /// /// /// - public static string ToMD5String(this string str) + public static string ToMd5String(this string str) { var md5 = MD5.Create(); var inputBytes = Encoding.UTF8.GetBytes(str); @@ -490,9 +384,9 @@ public static string ToMD5String(this string str) /// /// /// - public static string ToMD5String16(this string str) + public static string ToMd5String16(this string str) { - return str.ToMD5String().Substring(8, 16); + return str.ToMd5String().Substring(8, 16); } /// @@ -606,7 +500,7 @@ public static string Base64UrlDecode(this string base64UrlStr) /// public static byte[] ToSHA1Bytes(this string str) { - return str.ToSHA1Bytes(Encoding.UTF8); + return str.ToSha1Bytes(Encoding.UTF8); } /// @@ -615,7 +509,7 @@ public static byte[] ToSHA1Bytes(this string str) /// 字符串 /// 编码 /// - public static byte[] ToSHA1Bytes(this string str, Encoding encoding) + public static byte[] ToSha1Bytes(this string str, Encoding encoding) { SHA1 sha1 = new SHA1CryptoServiceProvider(); var inputBytes = encoding.GetBytes(str); @@ -630,7 +524,7 @@ public static byte[] ToSHA1Bytes(this string str, Encoding encoding) /// /// 字符串 /// - public static string ToSHA1String(this string str) + public static string ToSha1String(this string str) { return str.ToSHA1String(Encoding.UTF8); } @@ -643,7 +537,7 @@ public static string ToSHA1String(this string str) /// public static string ToSHA1String(this string str, Encoding encoding) { - var sha1Bytes = str.ToSHA1Bytes(encoding); + var sha1Bytes = str.ToSha1Bytes(encoding); var resStr = BitConverter.ToString(sha1Bytes); return resStr.Replace("-", "").ToLower(); } @@ -683,33 +577,6 @@ public static string ToHMACSHA256String(this string text, string secret) return Convert.ToBase64String(hashmessage).Replace('+', '-').Replace('/', '_').TrimEnd('='); } - /// - /// string转int - /// - /// 字符串 - /// - public static int ToInt(this string str) - { - str = str.Replace("\0", ""); - if (string.IsNullOrEmpty(str)) - return 0; - return Convert.ToInt32(str); - } - - /// - /// string转long - /// - /// 字符串 - /// - public static long ToLong(this string str) - { - str = str.Replace("\0", ""); - if (string.IsNullOrEmpty(str)) - return 0; - - return Convert.ToInt64(str); - } - /// /// 二进制字符串转为Int /// @@ -725,21 +592,6 @@ public static int ToInt_FromBinString(this string str) /// /// 数值 /// - public static int ToInt0X(this string str) - { - int num = Int32.Parse(str, NumberStyles.HexNumber); - return num; - } - - /// - /// 转换为double - /// - /// 字符串 - /// - public static double ToDouble(this string str) - { - return Convert.ToDouble(str); - } /// /// string转byte[] @@ -762,34 +614,6 @@ public static byte[] ToBytes(this string str, Encoding theEncoding) return theEncoding.GetBytes(str); } - /// - /// 将16进制字符串转为Byte数组 - /// - /// 16进制字符串(2个16进制字符表示一个Byte) - /// - public static byte[] To0XBytes(this string str) - { - List resBytes = new List(); - for (int i = 0; i < str.Length; i = i + 2) - { - string numStr = $@"{str[i]}{str[i + 1]}"; - resBytes.Add((byte)numStr.ToInt0X()); - } - - return resBytes.ToArray(); - } - - /// - /// 将ASCII码形式的字符串转为对应字节数组 - /// 注:一个字节一个ASCII码字符 - /// - /// 字符串 - /// - public static byte[] ToASCIIBytes(this string str) - { - return str.ToList().Select(x => (byte)x).ToArray(); - } - /// /// 删除Json字符串中键中的@符号 /// @@ -829,7 +653,7 @@ public static T ToEntity(this string json) break; case "System.Int32": - info?.SetValue(obj, match.Groups[1].ToString().ToInt(), null); + info?.SetValue(obj, match.Groups[1].ToString().ToInt32(), null); break; case "System.Int64": @@ -877,9 +701,8 @@ public static IPEndPoint ToIPEndPoint(this string str) try { var strArray = str.Split(':').ToArray(); - var addr = strArray[0]; var port = Convert.ToInt32(strArray[1]); - iPEndPoint = new IPEndPoint(IPAddress.Parse(addr), port); + iPEndPoint = new IPEndPoint(IPAddress.Parse(strArray[0]), port); } catch { @@ -901,20 +724,5 @@ public static TEnum ToEnum(this string enumText) where TEnum : struct return value; } - - /// - /// 是否为弱密码 - /// 注:密码必须包含数字、小写字母、大写字母和其他符号中的两种并且长度大于8 - /// - /// 密码 - /// - public static bool IsWeakPwd(this string pwd) - { - if (pwd.IsNullOrEmpty()) - throw new Exception("pwd不能为空"); - - const string pattern = "(^[0-9]+$)|(^[a-z]+$)|(^[A-Z]+$)|(^.{0,8}$)"; - return Regex.IsMatch(pwd, pattern); - } } } \ No newline at end of file