From f8cf71a6c8f5c69ef22404b1c4ce7545feceae9b Mon Sep 17 00:00:00 2001 From: zqlovejyc <943620963@qq.com> Date: Wed, 11 Nov 2020 15:05:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=831.1.0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81net5.0=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZqUtils.Core.Console.csproj | 2 +- ZqUtils.Core.Web/ZqUtils.Core.Web.csproj | 2 +- .../Extensions/Extensions.DateTime.cs | 14 +- ZqUtils.Core/Extensions/Extensions.Object.cs | 16 +- ZqUtils.Core/Helpers/CodeHelper.cs | 9 +- ZqUtils.Core/Helpers/EncodingHelper.cs | 35 ++-- ZqUtils.Core/Helpers/FileHelper.cs | 42 ++--- ZqUtils.Core/Helpers/PathHelper.cs | 32 ++-- ZqUtils.Core/Helpers/RabbitMqHelper.cs | 4 +- ZqUtils.Core/ZqUtils.Core.csproj | 165 +++++++++--------- 10 files changed, 155 insertions(+), 166 deletions(-) diff --git a/ZqUtils.Core.Console/ZqUtils.Core.Console.csproj b/ZqUtils.Core.Console/ZqUtils.Core.Console.csproj index 9416e8a..141efbb 100644 --- a/ZqUtils.Core.Console/ZqUtils.Core.Console.csproj +++ b/ZqUtils.Core.Console/ZqUtils.Core.Console.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net5.0 diff --git a/ZqUtils.Core.Web/ZqUtils.Core.Web.csproj b/ZqUtils.Core.Web/ZqUtils.Core.Web.csproj index 75134fc..e7542b4 100644 --- a/ZqUtils.Core.Web/ZqUtils.Core.Web.csproj +++ b/ZqUtils.Core.Web/ZqUtils.Core.Web.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 diff --git a/ZqUtils.Core/Extensions/Extensions.DateTime.cs b/ZqUtils.Core/Extensions/Extensions.DateTime.cs index e319a52..48770a0 100644 --- a/ZqUtils.Core/Extensions/Extensions.DateTime.cs +++ b/ZqUtils.Core/Extensions/Extensions.DateTime.cs @@ -241,8 +241,6 @@ public static int WeekOfYear(this DateTime @this, CultureInfo ci) /// 标识符“-” public static string ToDateTimeString(this DateTime @this, bool isRemoveSecond = false, string identifier = "-") { - if (@this == null) - return string.Empty; if (isRemoveSecond) return @this.ToString($"yyyy{identifier}MM{identifier}dd HH:mm"); return @this.ToString($"yyyy{identifier}MM{identifier}dd HH:mm:ss"); @@ -268,8 +266,6 @@ public static string ToDateTimeString(this DateTime? @this, bool isRemoveSecond /// 标识符“-” public static string ToDateString(this DateTime @this, string identifier = "-") { - if (@this == null) - return string.Empty; return @this.ToString($"yyyy{identifier}MM{identifier}dd"); } @@ -291,8 +287,6 @@ public static string ToDateString(this DateTime? @this, string identifier = "-") /// 日期 public static string ToTimeString(this DateTime @this) { - if (@this == null) - return string.Empty; return @this.ToString("HH:mm:ss"); } @@ -314,8 +308,6 @@ public static string ToTimeString(this DateTime? @this) /// 标识符“-” public static string ToMillisecondString(this DateTime @this, string identifier = "-") { - if (@this == null) - return string.Empty; return @this.ToString($"yyyy{identifier}MM{identifier}dd HH:mm:ss.fff"); } @@ -337,8 +329,6 @@ public static string ToMillisecondString(this DateTime? @this, string identifier /// 日期 public static string ToChineseDateString(this DateTime @this) { - if (@this == null) - return string.Empty; return @this.ToString("yyyy年MM月dd日"); } @@ -360,8 +350,6 @@ public static string ToChineseDateString(this DateTime? @this) /// 是否移除秒 public static string ToChineseDateTimeString(this DateTime @this, bool isRemoveSecond = false) { - if (@this == null) - return string.Empty; var result = new StringBuilder(@this.ToString("yyyy年MM月dd日 HH时mm分")); ; if (isRemoveSecond == false) result.Append($"{@this.Second}秒"); @@ -1445,4 +1433,4 @@ public static DateTime Yesterday(this DateTime @this) } #endregion } -} +} \ No newline at end of file diff --git a/ZqUtils.Core/Extensions/Extensions.Object.cs b/ZqUtils.Core/Extensions/Extensions.Object.cs index 7734a1c..f061906 100644 --- a/ZqUtils.Core/Extensions/Extensions.Object.cs +++ b/ZqUtils.Core/Extensions/Extensions.Object.cs @@ -5898,13 +5898,13 @@ public static T Chain(this T @this, Action action) /// the copied object. public static T DeepClone(this T @this) { - IFormatter formatter = new BinaryFormatter(); - using (var stream = new MemoryStream()) - { - formatter.Serialize(stream, @this); - stream.Seek(0, SeekOrigin.Begin); - return (T)formatter.Deserialize(stream); - } + // Don't serialize a null object, simply return the default for that object + if (@this == null) + return default; + + var deserializeSettings = new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace }; + var serializeSettings = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; + return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(@this, serializeSettings), deserializeSettings); } #endregion @@ -7173,4 +7173,4 @@ public static object GetValue(this object target, MemberInfo member) } #endregion } -} +} \ No newline at end of file diff --git a/ZqUtils.Core/Helpers/CodeHelper.cs b/ZqUtils.Core/Helpers/CodeHelper.cs index c3ba40f..a636bdb 100644 --- a/ZqUtils.Core/Helpers/CodeHelper.cs +++ b/ZqUtils.Core/Helpers/CodeHelper.cs @@ -17,16 +17,15 @@ #endregion using System; -using System.IO; using System.Collections.Generic; using System.DrawingCore; -using System.DrawingCore.Imaging; using System.DrawingCore.Drawing2D; +using System.DrawingCore.Imaging; +using System.IO; using ZXing; using ZXing.Common; using ZXing.QrCode; using ZXing.QrCode.Internal; -using ZXing.ZKWeb; /**************************** * [Author] 张强 * [Date] 2015-10-26 @@ -34,6 +33,8 @@ * **************************/ namespace ZqUtils.Core.Helpers { + using ZXing.ZKWeb; + /// /// 二维码/条形码/验证码工具类 /// @@ -406,4 +407,4 @@ public static byte[] CreateValidateGraphic(string validateCode) } #endregion } -} +} \ No newline at end of file diff --git a/ZqUtils.Core/Helpers/EncodingHelper.cs b/ZqUtils.Core/Helpers/EncodingHelper.cs index 04f0ef8..cf4b5a4 100644 --- a/ZqUtils.Core/Helpers/EncodingHelper.cs +++ b/ZqUtils.Core/Helpers/EncodingHelper.cs @@ -150,7 +150,9 @@ public static Encoding DetectBOM(this byte[] boms) if (boms[0] == 0xfe && boms[1] == 0xff) return Encoding.BigEndianUnicode; if (boms.Length < 3) return null; if (boms[0] == 0xef && boms[1] == 0xbb && boms[2] == 0xbf) return Encoding.UTF8; +#if !NET5_0 if (boms[0] == 0x2b && boms[1] == 0x2f && boms[2] == 0x76) return Encoding.UTF7; +#endif if (boms.Length < 4) return null; if (boms[0] == 0xff && boms[1] == 0xfe && boms[2] == 0 && boms[3] == 0) return Encoding.UTF32; if (boms[0] == 0 && boms[1] == 0 && boms[2] == 0xfe && boms[3] == 0xff) return Encoding.GetEncoding(12001); @@ -174,27 +176,24 @@ static Encoding DetectASCII(byte[] data) static bool IsMatch(byte[] data, Encoding encoding) { - if (encoding == null) encoding = Encoding.UTF8; - try + if (encoding == null) + encoding = Encoding.UTF8; + + var str = encoding.GetString(data); + var buf = encoding.GetBytes(str); + // 考虑到噪声干扰,只要0.9 + var score = buf.Length * 9 / 10; + var match = 0; + for (var i = 0; i < buf.Length; i++) { - var str = encoding.GetString(data); - var buf = encoding.GetBytes(str); - // 考虑到噪声干扰,只要0.9 - var score = buf.Length * 9 / 10; - var match = 0; - for (var i = 0; i < buf.Length; i++) + if (data[i] == buf[i]) { - if (data[i] == buf[i]) - { - match++; - if (match >= score) return true; - } + match++; + if (match >= score) + return true; } } - catch (Exception ex) - { - throw ex; - } + return false; } @@ -383,4 +382,4 @@ private static int DetectSuspiciousUTF8SequenceLength(byte[] buf, long pos) } #endregion } -} +} \ No newline at end of file diff --git a/ZqUtils.Core/Helpers/FileHelper.cs b/ZqUtils.Core/Helpers/FileHelper.cs index 49390d3..1ab7f68 100644 --- a/ZqUtils.Core/Helpers/FileHelper.cs +++ b/ZqUtils.Core/Helpers/FileHelper.cs @@ -175,9 +175,9 @@ public static void GetFile(string filePath, string fileName, bool isDeleteFile = } } } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -235,9 +235,9 @@ public static void GetFile(string fileName, string fullPath, long speed, bool is } } } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -302,9 +302,9 @@ public static void GetFile(string filePath, string fileName, string contentType, HttpContextHelper.Current.Response.Body.Write(bytes); HttpContextHelper.Current.Response.Body.Flush();//输出缓存,此部不可少 } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -352,9 +352,9 @@ public static void GetFileOfZip(string[] filePaths, string zipName, bool isDelet } } } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -411,9 +411,9 @@ public static byte[] GetFileOfZip(string[] filePaths, bool isDeleteFiles = false } return null; } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -470,9 +470,9 @@ public static async Task GetFileAsync(string filePath, string fileName, bool isD } } } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -531,9 +531,9 @@ public static async Task GetFileAsync(string fileName, string fullPath, long spe } } } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -566,9 +566,9 @@ public static async Task GetFileAsync(string filePath, string fileName, string c await HttpContextHelper.Current.Response.Body.WriteAsync(bytes, 0, bytes.Length); await HttpContextHelper.Current.Response.Body.FlushAsync();//输出缓存,此部不可少 } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -648,9 +648,9 @@ public static async Task GetFileOfZipAsync(string[] filePaths, string zipName, b } } } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -707,9 +707,9 @@ public static async Task GetFileOfZipAsync(string[] filePaths, bool isDe } return null; } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { @@ -1114,4 +1114,4 @@ public static string GetContentType(this string fileName) #endregion } #endregion -} +} \ No newline at end of file diff --git a/ZqUtils.Core/Helpers/PathHelper.cs b/ZqUtils.Core/Helpers/PathHelper.cs index e289bfc..6d4b83f 100644 --- a/ZqUtils.Core/Helpers/PathHelper.cs +++ b/ZqUtils.Core/Helpers/PathHelper.cs @@ -19,8 +19,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Reflection; using System.Text; using ZqUtils.Core.Extensions; /**************************** @@ -55,7 +53,7 @@ public static bool Mono { get { - if (_Mono == null) + if (_Mono == null) _Mono = Type.GetType("Mono.Runtime") != null; return _Mono.Value; } @@ -96,10 +94,10 @@ private static string GetPath(string path, int mode) default: break; } - if (dir.IsNullOrEmpty()) + if (dir.IsNullOrEmpty()) return Path.GetFullPath(path); // 处理网络路径 - if (path.StartsWith(@"\\")) + if (path.StartsWith(@"\\")) return Path.GetFullPath(path); // 考虑兼容Linux if (!Mono) @@ -138,7 +136,7 @@ private static string GetPath(string path, int mode) /// public static string GetFullPath(this string path) { - if (string.IsNullOrEmpty(path)) + if (string.IsNullOrEmpty(path)) return path; return GetPath(path, 1); @@ -154,7 +152,7 @@ public static string GetFullPath(this string path) /// public static string GetBasePath(this string path) { - if (string.IsNullOrEmpty(path)) + if (string.IsNullOrEmpty(path)) return path; return GetPath(path, 2); @@ -171,7 +169,7 @@ public static string GetBasePath(this string path) /// public static string GetCurrentPath(this string path) { - if (string.IsNullOrEmpty(path)) + if (string.IsNullOrEmpty(path)) return path; return GetPath(path, 3); @@ -213,7 +211,7 @@ public static string CombinePath(this string path, params string[] ps) { if (ps == null || ps.Length < 1) return path; - if (path == null) + if (path == null) path = string.Empty; foreach (var item in ps) { @@ -280,7 +278,7 @@ public static string ReadText(this FileInfo file, Encoding encoding = null) { using (var fs = file.OpenRead()) { - if (encoding == null) + if (encoding == null) encoding = fs.Detect() ?? Encoding.UTF8; using (var reader = new StreamReader(fs, encoding)) { @@ -300,7 +298,7 @@ public static FileInfo WriteText(this FileInfo file, string text, Encoding encod { using (var fs = file.OpenWrite()) { - if (encoding == null) + if (encoding == null) encoding = fs.Detect() ?? Encoding.UTF8; using (var writer = new StreamWriter(fs, encoding)) { @@ -375,7 +373,7 @@ public static IEnumerable GetAllFiles(this DirectoryInfo di, string ex { if (di == null || !di.Exists) yield break; - if (string.IsNullOrEmpty(exts)) + if (string.IsNullOrEmpty(exts)) exts = "*"; var opt = allSub ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; foreach (var pattern in exts.Split(";", "|", ",")) @@ -398,7 +396,7 @@ public static IEnumerable GetAllFiles(this DirectoryInfo di, string ex /// public static string[] CopyTo(this DirectoryInfo di, string destDirName, string exts = null, bool allSub = false, Action callback = null) { - if (!di.Exists) + if (!di.Exists) return new string[0]; var list = new List(); // 来源目录根,用于截断 @@ -426,7 +424,7 @@ public static string[] CopyTo(this DirectoryInfo di, string destDirName, string public static string[] CopyToIfNewer(this DirectoryInfo di, string destDirName, string exts = null, bool allSub = false, Action callback = null) { var dest = destDirName.AsDirectory(); - if (!dest.Exists) + if (!dest.Exists) return new string[0]; var list = new List(); // 目标目录根,用于截断 @@ -476,13 +474,13 @@ public static string[] CopyIfNewer(this DirectoryInfo di, string[] source, strin if (rs != null && rs.Length > 0) list.AddRange(rs); } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } } return list.ToArray(); } #endregion } -} +} \ No newline at end of file diff --git a/ZqUtils.Core/Helpers/RabbitMqHelper.cs b/ZqUtils.Core/Helpers/RabbitMqHelper.cs index 758d4eb..20dcbb6 100644 --- a/ZqUtils.Core/Helpers/RabbitMqHelper.cs +++ b/ZqUtils.Core/Helpers/RabbitMqHelper.cs @@ -1116,9 +1116,9 @@ public void Pull( { handler(msg); } - catch (Exception ex) + catch (Exception) { - throw ex; + throw; } finally { diff --git a/ZqUtils.Core/ZqUtils.Core.csproj b/ZqUtils.Core/ZqUtils.Core.csproj index 596ae55..0033f42 100644 --- a/ZqUtils.Core/ZqUtils.Core.csproj +++ b/ZqUtils.Core/ZqUtils.Core.csproj @@ -1,89 +1,92 @@  - - netstandard2.0;netstandard2.1 - true - 1.0.3.9 - Zq.Utils.Core - 张强 - .NET Standard2.0版本工具类 - Copyright © 2018-2020 , 张强 943620963@qq.com - - https://gitee.com/zqlovejyc/ZqUtils.Core - 1.优化ToDateTime扩展方法; -2.新增雪花算法生成Id工具类; -3.新增EncryptPassword密码加密方法; -4.优化IDataReader部分扩展方法; -5.修改SqlServer驱动,由System.Data.SqlClient改为Microsoft.Data.SqlClient; -6.新增基于AspectCore和Polly实现的重试、熔断等拦截特性HystrixAttribute; -7.优化appsettings配置,根据环境变量自动选择开发环境和正式环境配置; - 1.0.3.9 - 1.0.3.9 - true - Apache-2.0 - utils.png - https://gitee.com/zqlovejyc/ZqUtils.Core - git - Utility;Utils - + + netstandard2.0;netstandard2.1;net5.0 + true + 1.1.0 + Zq.Utils.Core + 张强 + .NET Standard2.1版本工具类 + Copyright © 2018-2020 , 张强 943620963@qq.com + + https://gitee.com/zqlovejyc/ZqUtils.Core + 1.修复MongoDbHelper所有涉及到Expression条件的删除、更新、查询方法调用错误bug; +2.优化MongoDbHelper分页查询; +3.新增Default扩展方法; +4.优化Substring扩展方法; +5.升级,支持net5.0; +6.升级Nuget包引用; + 1.1.0.0 + 1.1.0.0 + true + Apache-2.0 + utils.png + https://gitee.com/zqlovejyc/ZqUtils.Core + git + Utility;Utils + - - bin\Debug\netstandard2.1\ZqUtils.Core.xml - + + bin\Debug\netstandard2.0\ZqUtils.Core.xml + - - bin\Release\netstandard2.0\ZqUtils.Core.xml - + + bin\Release\netstandard2.1\ZqUtils.Core.xml + - - - - True - - - + + bin\Release\net5.0\ZqUtils.Core.xml + - - - Always - - + + + + True + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + Always + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file