Browse Source

list.ToDataTable当list数据为0条时,转换出一个没有数据只有表头的DataTalbe

懒得勤快 1 year ago
parent
commit
e9114779de

+ 7 - 2
Masuit.Tools.Abstractions/Database/DataTableHelper.cs

@@ -82,8 +82,13 @@ namespace Masuit.Tools.Database
         public static DataTable ToDataTable<T>(this IList<T> list, string tableName = null)
         {
             var result = new DataTable(tableName);
-            if (list.Count <= 0)
+            if (list.Count == 0)
             {
+                foreach (var property in typeof(T).GetProperties())
+                {
+                    // 添加表头列,列名为属性名
+                    result.Columns.Add(property.Name, property.PropertyType);
+                }
                 return result;
             }
 
@@ -227,4 +232,4 @@ namespace Masuit.Tools.Database
             return dt;
         }
     }
-}
+}

+ 8 - 8
Masuit.Tools.Abstractions/HtmlSanitizer/HtmlSanitizer.cs

@@ -467,6 +467,12 @@ namespace Ganss.Xss
 
         private void DoSanitize(IHtmlDocument dom, IParentNode context, string baseUrl = "")
         {
+            // remove disallowed tags
+            foreach (var tag in context.QuerySelectorAll("*").Where(t => !IsAllowedTag(t)).ToList())
+            {
+                RemoveTag(tag, RemoveReason.NotAllowedTag);
+            }
+
             // always encode text in raw data content
             foreach (var tag in context.QuerySelectorAll("*")
                 .Where(t => t is not IHtmlStyleElement
@@ -480,12 +486,6 @@ namespace Ganss.Xss
                     tag.SetInnerText(escapedHtml);
             }
 
-            // remove disallowed tags
-            foreach (var tag in context.QuerySelectorAll("*").Where(t => !IsAllowedTag(t)).ToList())
-            {
-                RemoveTag(tag, RemoveReason.NotAllowedTag);
-            }
-
             SanitizeStyleSheets(dom, baseUrl);
 
             // cleanup attributes
@@ -628,7 +628,7 @@ namespace Ganss.Xss
                         OnPostProcessNode(e);
                         if (e.ReplacementNodes.Any())
                         {
-                            ((IChildNode)node).Replace(e.ReplacementNodes.ToArray());
+                            ((IChildNode)node).Replace([.. e.ReplacementNodes]);
                         }
                     }
                 }
@@ -862,7 +862,7 @@ namespace Ganss.Xss
             if (!e.Cancel)
             {
                 if (KeepChildNodes && tag.HasChildNodes)
-                    tag.Replace(tag.ChildNodes.ToArray());
+                    tag.Replace([.. tag.ChildNodes]);
                 else
                     tag.Remove();
             }

+ 1 - 1
Masuit.Tools.Abstractions/Masuit.Tools.Abstractions.csproj

@@ -3,7 +3,7 @@
         <TargetFrameworks>netstandard2.0;netstandard2.1;net461;net5;net6;net7;net8</TargetFrameworks>
         <LangVersion>latest</LangVersion>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-        <Version>2.6.8.1</Version>
+        <Version>2.6.8.2</Version>
         <Authors>懒得勤快</Authors>
         <Description>全龄段友好的C#万能工具库,码数吐司库,不管你是菜鸟新手还是骨灰级玩家都能轻松上手,Masuit.Tools基础公共库(适用于.NET4.6.1/.NET Standard2.0及以上项目),包含一些常用的操作类,大都是静态类,加密解密,反射操作,Excel简单导出,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载和FTP客户端,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展等常用封装。
             官网教程:https://tools.masuit.org

+ 1 - 1
Masuit.Tools.AspNetCore/Masuit.Tools.AspNetCore.csproj

@@ -18,7 +18,7 @@
         <Product>Masuit.Tools.AspNetCore</Product>
         <PackageId>Masuit.Tools.AspNetCore</PackageId>
         <LangVersion>latest</LangVersion>
-        <Version>1.2.8.1</Version>
+        <Version>1.2.8.2</Version>
         <RepositoryType></RepositoryType>
         <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
         <FileVersion>1.1.9</FileVersion>

+ 1 - 1
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -6,7 +6,7 @@
 官网教程:https://tools.masuit.org
 github:https://github.com/ldqk/Masuit.Tools
         </Description>
-        <Version>2.6.8.1</Version>
+        <Version>2.6.8.2</Version>
         <Copyright>Copyright © 懒得勤快</Copyright>
         <PackageProjectUrl>https://github.com/ldqk/Masuit.Tools</PackageProjectUrl>
         <PackageTags>Masuit.Tools,工具库,Utility,Crypt,Extensions</PackageTags>

+ 1 - 1
Masuit.Tools.Excel/Masuit.Tools.Excel.csproj

@@ -3,7 +3,7 @@
         <TargetFramework>netstandard2.0</TargetFramework>
         <LangVersion>latest</LangVersion>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-        <Version>1.2.8</Version>
+        <Version>1.2.8.1</Version>
         <Authors>懒得勤快</Authors>
         <Description>Masuit.Tools.Excel导出库,支持一些简单数据的导出,支持图片列</Description>
         <Copyright>懒得勤快</Copyright>

+ 1 - 1
Masuit.Tools.Net45/package.nuspec

@@ -2,7 +2,7 @@
 <package>
   <metadata>
     <id>Masuit.Tools.Net45</id>
-    <version>2.6.8.1</version>
+    <version>2.6.8.2</version>
     <title>Masuit.Tools</title>
     <authors>懒得勤快</authors>
     <owners>masuit.com</owners>

+ 1 - 1
Masuit.Tools/Masuit.Tools.csproj

@@ -205,7 +205,7 @@
       <Version>1.7.0</Version>
     </PackageReference>
     <PackageReference Include="HtmlSanitizer">
-      <Version>8.0.746</Version>
+      <Version>8.0.795</Version>
     </PackageReference>
     <PackageReference Include="Microsoft.AspNet.Mvc">
       <Version>5.3.0</Version>

+ 1 - 1
Masuit.Tools/package.nuspec

@@ -2,7 +2,7 @@
 <package>
   <metadata>
     <id>Masuit.Tools.Net</id>
-    <version>2.6.8.1</version>
+    <version>2.6.8.2</version>
     <title>Masuit.Tools</title>
     <authors>懒得勤快</authors>
     <owners>masuit.com</owners>

+ 2 - 2
Test/Masuit.Tools.Test/Masuit.Tools.Test.csproj

@@ -95,7 +95,7 @@
       <Version>2.0.0</Version>
     </PackageReference>
     <PackageReference Include="Moq">
-      <Version>4.20.69</Version>
+      <Version>4.20.70</Version>
     </PackageReference>
     <PackageReference Include="MSTest.TestAdapter">
       <Version>3.1.1</Version>
@@ -104,7 +104,7 @@
       <Version>3.1.1</Version>
     </PackageReference>
     <PackageReference Include="NUnit">
-      <Version>3.14.0</Version>
+      <Version>4.0.0</Version>
     </PackageReference>
     <PackageReference Include="System.Runtime.CompilerServices.Unsafe">
       <Version>6.0.0</Version>