From a36c2d036cd2e1a1529175de4fe1523c0a18ce96 Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Tue, 29 Sep 2020 12:56:43 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=20=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E7=B1=BB=E6=B3=A8=E9=87=8A=EF=BC=8C=E5=9F=BA=E7=B1=BB=E5=9C=A8?= =?UTF-8?q?=E5=85=B6=E4=BB=96=20Assembly=20=E6=97=B6=E4=B9=9F=E8=83=BD?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql.DbContext/FreeSql.DbContext.xml | 4 +- .../MySql/Curd/MySqlSelectTest.cs | 4 +- FreeSql/Internal/CommonUtils.cs | 109 ++++++++++-------- 3 files changed, 64 insertions(+), 53 deletions(-) diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index 7ff55af8..743835e4 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -532,9 +532,7 @@ - - -Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])"> + 批量注入 Repository,可以参考代码自行调整 diff --git a/FreeSql.Tests/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs b/FreeSql.Tests/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs index 292da596..2d0bacb3 100644 --- a/FreeSql.Tests/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs +++ b/FreeSql.Tests/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs @@ -825,13 +825,13 @@ LEFT JOIN `TestTypeParentInfo` a__Type__Parent ON a__Type__Parent.`Id` = a__Type .WhereIf(false, a => b.ParentId == 20)); sql = query2.ToSql().Replace("\r\n", ""); Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a, `TestTypeInfo` b, `TestTypeParentInfo` c", sql); - query2.ToList(); + query2.Limit(100).ToList(); //������϶����㲻�� query = select.WhereIf(false, "a.clicks > 100 and a.id = ?id", new { id = 10 }); sql = query.ToSql().Replace("\r\n", ""); Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a", sql); - query.ToList(); + query.Limit(100).ToList(); } [Fact] public void WhereExists() diff --git a/FreeSql/Internal/CommonUtils.cs b/FreeSql/Internal/CommonUtils.cs index 9b2ee4f5..6b8f85d0 100644 --- a/FreeSql/Internal/CommonUtils.cs +++ b/FreeSql/Internal/CommonUtils.cs @@ -451,56 +451,69 @@ namespace FreeSql.Internal /// Dict:key=属性名,value=注释 public static Dictionary GetProperyCommentBySummary(Type type) { - if (type.Assembly.IsDynamic) return null; - //动态生成的程序集,访问不了 Assembly.Location/Assembly.CodeBase - var regex = new Regex(@"\.(dll|exe)", RegexOptions.IgnoreCase); - var xmlPath = regex.Replace(type.Assembly.Location, ".xml"); - if (File.Exists(xmlPath) == false) + return LocalGetComment(type, 0); + + Dictionary LocalGetComment(Type localType, int level) { - if (string.IsNullOrEmpty(type.Assembly.CodeBase)) return null; - xmlPath = regex.Replace(type.Assembly.CodeBase, ".xml"); - if (xmlPath.StartsWith("file:///") && Uri.TryCreate(xmlPath, UriKind.Absolute, out var tryuri)) - xmlPath = tryuri.LocalPath; - if (File.Exists(xmlPath) == false) return null; + if (localType.Assembly.IsDynamic) return null; + //动态生成的程序集,访问不了 Assembly.Location/Assembly.CodeBase + var regex = new Regex(@"\.(dll|exe)", RegexOptions.IgnoreCase); + var xmlPath = regex.Replace(localType.Assembly.Location, ".xml"); + if (File.Exists(xmlPath) == false) + { + if (string.IsNullOrEmpty(localType.Assembly.CodeBase)) return null; + xmlPath = regex.Replace(localType.Assembly.CodeBase, ".xml"); + if (xmlPath.StartsWith("file:///") && Uri.TryCreate(xmlPath, UriKind.Absolute, out var tryuri)) + xmlPath = tryuri.LocalPath; + if (File.Exists(xmlPath) == false) return null; + } + + var dic = new Dictionary(); + var sReader = new StringReader(File.ReadAllText(xmlPath)); + using (var xmlReader = XmlReader.Create(sReader)) + { + XPathDocument xpath = null; + try + { + xpath = new XPathDocument(xmlReader); + } + catch + { + return null; + } + var xmlNav = xpath.CreateNavigator(); + + var className = (localType.IsNested ? $"{localType.Namespace}.{localType.DeclaringType.Name}.{localType.Name}" : $"{localType.Namespace}.{localType.Name}").Trim('.'); + var node = xmlNav.SelectSingleNode($"/doc/members/member[@name='T:{className}']/summary"); + if (node != null) + { + var comment = node.InnerXml.Trim(' ', '\r', '\n', '\t'); + if (string.IsNullOrEmpty(comment) == false) dic.Add("", comment); //class注释 + } + + var props = localType.GetPropertiesDictIgnoreCase().Values; + foreach (var prop in props) + { + className = (prop.DeclaringType.IsNested ? $"{prop.DeclaringType.Namespace}.{prop.DeclaringType.DeclaringType.Name}.{prop.DeclaringType.Name}" : $"{prop.DeclaringType.Namespace}.{prop.DeclaringType.Name}").Trim('.'); + node = xmlNav.SelectSingleNode($"/doc/members/member[@name='P:{className}.{prop.Name}']/summary"); + if (node == null) + { + if (level == 0 && prop.DeclaringType.Assembly != localType.Assembly) + { + var cbs = LocalGetComment(prop.DeclaringType, level + 1); + if (cbs != null && cbs.TryGetValue(prop.Name, out var otherComment) && string.IsNullOrEmpty(otherComment) == false) + dic.Add(prop.Name, otherComment); + } + continue; + } + var comment = node.InnerXml.Trim(' ', '\r', '\n', '\t'); + if (string.IsNullOrEmpty(comment)) continue; + + dic.Add(prop.Name, comment); + } + } + return dic; } - - var dic = new Dictionary(); - var sReader = new StringReader(File.ReadAllText(xmlPath)); - using (var xmlReader = XmlReader.Create(sReader)) - { - XPathDocument xpath = null; - try - { - xpath = new XPathDocument(xmlReader); - } - catch - { - return null; - } - var xmlNav = xpath.CreateNavigator(); - - var className = (type.IsNested ? $"{type.Namespace}.{type.DeclaringType.Name}.{type.Name}" : $"{type.Namespace}.{type.Name}").Trim('.'); - var node = xmlNav.SelectSingleNode($"/doc/members/member[@name='T:{className}']/summary"); - if (node != null) - { - var comment = node.InnerXml.Trim(' ', '\r', '\n', '\t'); - if (string.IsNullOrEmpty(comment) == false) dic.Add("", comment); //class注释 - } - - var props = type.GetPropertiesDictIgnoreCase().Values; - foreach (var prop in props) - { - className = (prop.DeclaringType.IsNested ? $"{prop.DeclaringType.Namespace}.{prop.DeclaringType.DeclaringType.Name}.{prop.DeclaringType.Name}" : $"{prop.DeclaringType.Namespace}.{prop.DeclaringType.Name}").Trim('.'); - node = xmlNav.SelectSingleNode($"/doc/members/member[@name='P:{className}.{prop.Name}']/summary"); - if (node == null) continue; - var comment = node.InnerXml.Trim(' ', '\r', '\n', '\t'); - if (string.IsNullOrEmpty(comment)) continue; - - dic.Add(prop.Name, comment); - } - } - - return dic; } public static void PrevReheatConnectionPool(ObjectPool pool, int minPoolSize)