mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 实体类注释,基类在其他 Assembly 时也能读取;
This commit is contained in:
parent
35069609de
commit
a36c2d036c
@ -532,9 +532,7 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
</members>
|
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||||
</doc>
|
|
||||||
Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
|
||||||
<summary>
|
<summary>
|
||||||
批量注入 Repository,可以参考代码自行调整
|
批量注入 Repository,可以参考代码自行调整
|
||||||
</summary>
|
</summary>
|
||||||
|
@ -825,13 +825,13 @@ LEFT JOIN `TestTypeParentInfo` a__Type__Parent ON a__Type__Parent.`Id` = a__Type
|
|||||||
.WhereIf(false, a => b.ParentId == 20));
|
.WhereIf(false, a => b.ParentId == 20));
|
||||||
sql = query2.ToSql().Replace("\r\n", "");
|
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);
|
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();
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||||
query = select.WhereIf(false, "a.clicks > 100 and a.id = ?id", new { id = 10 });
|
query = select.WhereIf(false, "a.clicks > 100 and a.id = ?id", new { id = 10 });
|
||||||
sql = query.ToSql().Replace("\r\n", "");
|
sql = query.ToSql().Replace("\r\n", "");
|
||||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a", sql);
|
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]
|
[Fact]
|
||||||
public void WhereExists()
|
public void WhereExists()
|
||||||
|
@ -451,14 +451,18 @@ namespace FreeSql.Internal
|
|||||||
/// <returns>Dict:key=属性名,value=注释</returns>
|
/// <returns>Dict:key=属性名,value=注释</returns>
|
||||||
public static Dictionary<string, string> GetProperyCommentBySummary(Type type)
|
public static Dictionary<string, string> GetProperyCommentBySummary(Type type)
|
||||||
{
|
{
|
||||||
if (type.Assembly.IsDynamic) return null;
|
return LocalGetComment(type, 0);
|
||||||
|
|
||||||
|
Dictionary<string, string> LocalGetComment(Type localType, int level)
|
||||||
|
{
|
||||||
|
if (localType.Assembly.IsDynamic) return null;
|
||||||
//动态生成的程序集,访问不了 Assembly.Location/Assembly.CodeBase
|
//动态生成的程序集,访问不了 Assembly.Location/Assembly.CodeBase
|
||||||
var regex = new Regex(@"\.(dll|exe)", RegexOptions.IgnoreCase);
|
var regex = new Regex(@"\.(dll|exe)", RegexOptions.IgnoreCase);
|
||||||
var xmlPath = regex.Replace(type.Assembly.Location, ".xml");
|
var xmlPath = regex.Replace(localType.Assembly.Location, ".xml");
|
||||||
if (File.Exists(xmlPath) == false)
|
if (File.Exists(xmlPath) == false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(type.Assembly.CodeBase)) return null;
|
if (string.IsNullOrEmpty(localType.Assembly.CodeBase)) return null;
|
||||||
xmlPath = regex.Replace(type.Assembly.CodeBase, ".xml");
|
xmlPath = regex.Replace(localType.Assembly.CodeBase, ".xml");
|
||||||
if (xmlPath.StartsWith("file:///") && Uri.TryCreate(xmlPath, UriKind.Absolute, out var tryuri))
|
if (xmlPath.StartsWith("file:///") && Uri.TryCreate(xmlPath, UriKind.Absolute, out var tryuri))
|
||||||
xmlPath = tryuri.LocalPath;
|
xmlPath = tryuri.LocalPath;
|
||||||
if (File.Exists(xmlPath) == false) return null;
|
if (File.Exists(xmlPath) == false) return null;
|
||||||
@ -479,7 +483,7 @@ namespace FreeSql.Internal
|
|||||||
}
|
}
|
||||||
var xmlNav = xpath.CreateNavigator();
|
var xmlNav = xpath.CreateNavigator();
|
||||||
|
|
||||||
var className = (type.IsNested ? $"{type.Namespace}.{type.DeclaringType.Name}.{type.Name}" : $"{type.Namespace}.{type.Name}").Trim('.');
|
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");
|
var node = xmlNav.SelectSingleNode($"/doc/members/member[@name='T:{className}']/summary");
|
||||||
if (node != null)
|
if (node != null)
|
||||||
{
|
{
|
||||||
@ -487,21 +491,30 @@ namespace FreeSql.Internal
|
|||||||
if (string.IsNullOrEmpty(comment) == false) dic.Add("", comment); //class注释
|
if (string.IsNullOrEmpty(comment) == false) dic.Add("", comment); //class注释
|
||||||
}
|
}
|
||||||
|
|
||||||
var props = type.GetPropertiesDictIgnoreCase().Values;
|
var props = localType.GetPropertiesDictIgnoreCase().Values;
|
||||||
foreach (var prop in props)
|
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('.');
|
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");
|
node = xmlNav.SelectSingleNode($"/doc/members/member[@name='P:{className}.{prop.Name}']/summary");
|
||||||
if (node == null) continue;
|
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');
|
var comment = node.InnerXml.Trim(' ', '\r', '\n', '\t');
|
||||||
if (string.IsNullOrEmpty(comment)) continue;
|
if (string.IsNullOrEmpty(comment)) continue;
|
||||||
|
|
||||||
dic.Add(prop.Name, comment);
|
dic.Add(prop.Name, comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dic;
|
return dic;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void PrevReheatConnectionPool(ObjectPool<DbConnection> pool, int minPoolSize)
|
public static void PrevReheatConnectionPool(ObjectPool<DbConnection> pool, int minPoolSize)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user