Skip to content

Commit 7951c00

Browse files
authored
Merge branch 'master' into patch-1
2 parents 51dbf79 + a7f14b8 commit 7951c00

2 files changed

Lines changed: 38 additions & 37 deletions

File tree

Extensions/FreeSql.Extensions.LazyLoading/LazyLoadingComplier.cs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,33 @@ public class LazyLoadingComplier
2323
// return complier.GetAssembly();
2424
//}
2525

26-
/* 于2026-03-12注释:会导致单文件发布时,导航功能报错。
27-
internal static Lazy<CSScriptLib.RoslynEvaluator> _compiler = new Lazy<CSScriptLib.RoslynEvaluator>(() =>
28-
{
29-
var compiler = new CSScriptLib.RoslynEvaluator();
30-
compiler.DisableReferencingFromCode = false;
31-
compiler
32-
.ReferenceAssemblyOf<IFreeSql>()
33-
.ReferenceDomainAssemblies();
34-
return compiler;
35-
});
26+
/*2026-3-13:应用单文件发布模式,导航功能报错。
27+
internal static Lazy<CSScriptLib.RoslynEvaluator> _compiler = new Lazy<CSScriptLib.RoslynEvaluator>(() =>
28+
{
29+
var compiler = new CSScriptLib.RoslynEvaluator();
30+
compiler.DisableReferencingFromCode = false;
31+
compiler
32+
.ReferenceAssemblyOf<IFreeSql>()
33+
.ReferenceDomainAssemblies();
34+
return compiler;
35+
});
3636
37-
public static Assembly CompileCode(string cscode)
38-
{
39-
return _compiler.Value.CompileCode(cscode);
40-
}
41-
*/
42-
/*
43-
* 于2026-03-12:删除CS-Script.Core库,改用官方的库 Microsoft.CodeAnalysis.CSharp。
44-
*/
45-
private static readonly HashSet<MetadataReference> references = new HashSet<MetadataReference>(from eve in AppDomain.CurrentDomain.GetAssemblies().AsParallel()
46-
let ass = CreateMetadataReference(eve)
47-
where ass != null
48-
select ass);
37+
public static Assembly CompileCode(string cscode)
38+
{
39+
return _compiler.Value.CompileCode(cscode);
40+
}
41+
*/
42+
43+
//2026-3-13:删除CS-Script.Core库,改用官方的库 Microsoft.CodeAnalysis.CSharp。
44+
private static readonly HashSet<MetadataReference> references = new();
4945
static LazyLoadingComplier()
5046
{
47+
foreach (var eve in AppDomain.CurrentDomain.GetAssemblies().AsParallel())
48+
{
49+
var ass = CreateMetadataReference(eve);
50+
if (ass != null)
51+
references.Add(ass);
52+
}
5153
references.Add(CreateMetadataReference(typeof(String).Assembly));
5254
references.Add(CreateMetadataReference(Assembly.GetEntryAssembly()));
5355
references.Add(CreateMetadataReference(Assembly.GetCallingAssembly()));
@@ -57,20 +59,18 @@ static LazyLoadingComplier()
5759
public static Assembly CompileCode(string cscode)
5860
{
5961
var tree = CSharpSyntaxTree.ParseText(cscode);
60-
using (var ms = new MemoryStream())
62+
using var ms = new MemoryStream();
63+
var result = CSharpCompilation.Create("DynamicAssembly")
64+
.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release, reportSuppressedDiagnostics: false))
65+
.AddReferences(references)
66+
.AddSyntaxTrees(tree).Emit(ms);
67+
if (result.Success)
6168
{
62-
var result = CSharpCompilation.Create("DynamicAssembly")
63-
.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release, reportSuppressedDiagnostics: false))
64-
.AddReferences(references)
65-
.AddSyntaxTrees(tree).Emit(ms);
66-
if (result.Success)
67-
{
68-
return Assembly.Load(ms.ToArray());
69-
}
70-
else
71-
{
72-
throw new Exception(string.Join(Environment.NewLine, from eve in result.Diagnostics select eve.ToString()));
73-
}
69+
return Assembly.Load(ms.ToArray());
70+
}
71+
else
72+
{
73+
throw new Exception(string.Join(Environment.NewLine, from eve in result.Diagnostics select eve.ToString()));
7474
}
7575
}
7676
public static MetadataReference CreateMetadataReference(Assembly assembly)
@@ -88,6 +88,7 @@ public static MetadataReference CreateMetadataReference(Assembly assembly)
8888
}
8989
return null;
9090
}
91+
9192
#else
9293

9394
public static Assembly CompileCode(string cscode)

FreeSql/Extensions/FreeSqlGlobalExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ internal static ConstructorInfo InternalGetTypeConstructor0OrFirst(this Type tha
197197
static ConcurrentDictionary<Type, Dictionary<string, PropertyInfo>> _dicGetPropertiesDictIgnoreCase = new ConcurrentDictionary<Type, Dictionary<string, PropertyInfo>>();
198198
public static Dictionary<string, PropertyInfo> GetPropertiesDictIgnoreCase(this Type that) => that == null ? null : _dicGetPropertiesDictIgnoreCase.GetOrAdd(that, tp =>
199199
{
200-
var props = that.GetProperties().GroupBy(p => p.DeclaringType).Reverse().SelectMany(p => p); //将基类的属性位置放在前面 #164
200+
var props = that.GetProperties(BindingFlags.Instance | BindingFlags.Public).GroupBy(p => p.DeclaringType).Reverse().SelectMany(p => p); //将基类的属性位置放在前面 #164
201201
var dict = new Dictionary<string, PropertyInfo>(StringComparer.CurrentCultureIgnoreCase);
202202
foreach (var prop in props)
203203
{
@@ -1778,4 +1778,4 @@ public enum SqlServerLock
17781778
TabLockX = 4096,
17791779
XLock = 8192,
17801780
NoWait = 16384
1781-
}
1781+
}

0 commit comments

Comments
 (0)