Explorar o código

模版引擎增强

懒得勤快 %!s(int64=5) %!d(string=hai) anos
pai
achega
0dedfd7bf3

+ 5 - 5
Masuit.Tools.Core/AspNetCore/DbSetExtensions.cs

@@ -74,17 +74,17 @@ namespace Masuit.Tools.Core.AspNetCore
             {
                 // 获取主键字段
                 var dataType = typeof(T);
-                var key_ignoreFields = dataType.GetProperties().Where(p => p.GetCustomAttribute<KeyAttribute>() != null || p.GetCustomAttribute<UpdateIgnoreAttribute>() != null).ToList();
-                if (!key_ignoreFields.Any())
+                var keyIgnoreFields = dataType.GetProperties().Where(p => p.GetCustomAttribute<KeyAttribute>() != null || p.GetCustomAttribute<UpdateIgnoreAttribute>() != null).ToList();
+                if (!keyIgnoreFields.Any())
                 {
                     string idName = dataType.Name + "Id";
-                    key_ignoreFields = dataType.GetProperties().Where(p => p.Name.Equals("Id", StringComparison.OrdinalIgnoreCase) || p.Name.Equals(idName, StringComparison.OrdinalIgnoreCase)).ToList();
+                    keyIgnoreFields = dataType.GetProperties().Where(p => p.Name.Equals("Id", StringComparison.OrdinalIgnoreCase) || p.Name.Equals(idName, StringComparison.OrdinalIgnoreCase)).ToList();
                 }
                 // 更新所有非主键属性
                 foreach (var p in typeof(T).GetProperties().Where(p => p.GetSetMethod() != null && p.GetGetMethod() != null))
                 {
                     // 忽略主键和被忽略的字段
-                    if (key_ignoreFields.Any(x => x.Name == p.Name))
+                    if (keyIgnoreFields.Any(x => x.Name == p.Name))
                     {
                         continue;
                     }
@@ -96,7 +96,7 @@ namespace Masuit.Tools.Core.AspNetCore
                     }
                 }
 
-                foreach (var idField in key_ignoreFields.Where(p => p.GetSetMethod() != null && p.GetGetMethod() != null))
+                foreach (var idField in keyIgnoreFields.Where(p => p.GetSetMethod() != null && p.GetGetMethod() != null))
                 {
                     var existingValue = idField.GetValue(item);
                     if (idField.GetValue(entity) != existingValue)

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

@@ -21,6 +21,7 @@ github:https://github.com/ldqk/Masuit.Tools</Description>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
+    <UserSecretsId>830c282f-f7c1-42be-8651-4cd06ac8e73f</UserSecretsId>
   </PropertyGroup>
 
   <ItemGroup>

+ 3 - 3
Masuit.Tools.Core/Properties/PublishProfiles/FolderProfile.pubxml

@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-This file is used by the publish/package process of your project. You can customize the behavior of this process
-by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
+https://go.microsoft.com/fwlink/?LinkID=208121. 
 -->
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <PublishProtocol>FileSystem</PublishProtocol>
     <Configuration>Release</Configuration>
-    <TargetFramework>netstandard2.0</TargetFramework>
+    <TargetFramework>netstandard2.1</TargetFramework>
     <PublishDir>bin\Release\PublishOutput</PublishDir>
+    <Platform>Any CPU</Platform>
   </PropertyGroup>
 </Project>

+ 7 - 3
Masuit.Tools/Strings/Template.cs

@@ -34,13 +34,17 @@ namespace Masuit.Tools.Strings
         /// <summary>
         /// 渲染模板
         /// </summary>
+        /// <param name="check">是否检查未使用的模板变量</param>
         /// <returns></returns>
-        public string Render()
+        public string Render(bool check = false)
         {
             var mc = Regex.Matches(Content, @"\{\{.+?\}\}");
-            foreach (Match m in mc)
+            if (check)
             {
-                throw new ArgumentException($"模版变量{m.Value}未被使用");
+                foreach (Match m in mc)
+                {
+                    throw new ArgumentException($"模版变量{m.Value}未被使用");
+                }
             }
 
             return Content;