mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-07-17 17:43:05 +08:00
initial commit
This commit is contained in:
@ -0,0 +1,42 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.1;netstandard2.0;net45;net40</TargetFrameworks>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>FreeSql;ncc;YeXiangQin</Authors>
|
||||
<Description>FreeSql 扩展包,可实现【延时加载】属性.</Description>
|
||||
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageTags>FreeSql;ORM</PackageTags>
|
||||
<PackageId>$(AssemblyName)</PackageId>
|
||||
<PackageIcon>logo.png</PackageIcon>
|
||||
<Title>$(AssemblyName)</Title>
|
||||
<IsPackable>true</IsPackable>
|
||||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
|
||||
<Version>3.2.833</Version>
|
||||
<PackageReadmeFile>readme.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../../readme.md" Pack="true" PackagePath="\"/>
|
||||
<None Include="../../logo.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
|
||||
<PackageReference Include="CS-Script.Core" Version="1.3.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<PackageReference Include="CS-Script.Core" Version="1.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'netstandard2.0'">
|
||||
<DefineConstants>ns20;netstandard20</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace FreeSql.Extensions.LazyLoading
|
||||
{
|
||||
|
||||
public class LazyLoadingComplier
|
||||
{
|
||||
|
||||
#if ns20
|
||||
//public static Assembly CompileCode(string cscode)
|
||||
//{
|
||||
// Natasha.AssemblyComplier complier = new Natasha.AssemblyComplier();
|
||||
// //complier.Domain = DomainManagment.Random;
|
||||
// complier.Add(cscode);
|
||||
// return complier.GetAssembly();
|
||||
//}
|
||||
|
||||
internal static Lazy<CSScriptLib.RoslynEvaluator> _compiler = new Lazy<CSScriptLib.RoslynEvaluator>(() =>
|
||||
{
|
||||
var compiler = new CSScriptLib.RoslynEvaluator();
|
||||
compiler.DisableReferencingFromCode = false;
|
||||
compiler
|
||||
.ReferenceAssemblyOf<IFreeSql>()
|
||||
.ReferenceDomainAssemblies();
|
||||
return compiler;
|
||||
});
|
||||
|
||||
public static Assembly CompileCode(string cscode)
|
||||
{
|
||||
return _compiler.Value.CompileCode(cscode);
|
||||
}
|
||||
#else
|
||||
|
||||
public static Assembly CompileCode(string cscode)
|
||||
{
|
||||
|
||||
var files = Directory.GetFiles(Directory.GetParent(Type.GetType("IFreeSql, FreeSql").Assembly.Location).FullName);
|
||||
using (var compiler = CodeDomProvider.CreateProvider("cs"))
|
||||
{
|
||||
var objCompilerParameters = new CompilerParameters();
|
||||
objCompilerParameters.ReferencedAssemblies.Add("System.dll");
|
||||
objCompilerParameters.ReferencedAssemblies.Add("System.Core.dll");
|
||||
objCompilerParameters.ReferencedAssemblies.Add("FreeSql.dll");
|
||||
foreach (var dll in files)
|
||||
{
|
||||
if (!dll.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) &&
|
||||
!dll.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) continue;
|
||||
|
||||
//Console.WriteLine(dll);
|
||||
var dllName = string.Empty;
|
||||
var idx = dll.LastIndexOf('/');
|
||||
if (idx != -1) dllName = dll.Substring(idx + 1);
|
||||
else
|
||||
{
|
||||
idx = dll.LastIndexOf('\\');
|
||||
if (idx != -1) dllName = dll.Substring(idx + 1);
|
||||
}
|
||||
if (string.IsNullOrEmpty(dllName)) continue;
|
||||
try
|
||||
{
|
||||
var ass = Assembly.LoadFile(dll);
|
||||
objCompilerParameters.ReferencedAssemblies.Add(dllName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
objCompilerParameters.GenerateExecutable = false;
|
||||
objCompilerParameters.GenerateInMemory = true;
|
||||
|
||||
CompilerResults cr = compiler.CompileAssemblyFromSource(objCompilerParameters, cscode);
|
||||
|
||||
if (cr.Errors.Count > 0)
|
||||
throw new Exception(cr.Errors[0].ErrorText);
|
||||
|
||||
return cr.CompiledAssembly;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
BIN
Extensions/FreeSql.Extensions.LazyLoading/key.snk
Normal file
BIN
Extensions/FreeSql.Extensions.LazyLoading/key.snk
Normal file
Binary file not shown.
Reference in New Issue
Block a user