This commit is contained in:
28810 2019-12-19 10:55:26 +08:00
parent e03aaed55b
commit a23a49163e

View File

@ -33,16 +33,16 @@ namespace FreeSql.Extensions.LazyLoading
} }
#else #else
public static Assembly CompileCode(string cscode)
public static Assembly CompileCode(string cscode) { {
var files = Directory.GetFiles(Directory.GetParent(Type.GetType("IFreeSql, FreeSql").Assembly.Location).FullName); var files = Directory.GetFiles(Directory.GetParent(Type.GetType("IFreeSql, FreeSql").Assembly.Location).FullName);
using (var compiler = CodeDomProvider.CreateProvider("cs")) { using (var compiler = CodeDomProvider.CreateProvider("cs"))
{
var objCompilerParameters = new CompilerParameters(); var objCompilerParameters = new CompilerParameters();
objCompilerParameters.ReferencedAssemblies.Add("System.dll"); objCompilerParameters.ReferencedAssemblies.Add("System.dll");
objCompilerParameters.ReferencedAssemblies.Add("System.Core.dll"); objCompilerParameters.ReferencedAssemblies.Add("System.Core.dll");
objCompilerParameters.ReferencedAssemblies.Add("FreeSql.dll"); objCompilerParameters.ReferencedAssemblies.Add("FreeSql.dll");
foreach (var dll in files) foreach (var dll in files)
{ {
if (!dll.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) && if (!dll.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) &&
@ -69,16 +69,16 @@ namespace FreeSql.Extensions.LazyLoading
} }
} }
objCompilerParameters.GenerateExecutable = false; objCompilerParameters.GenerateExecutable = false;
objCompilerParameters.GenerateInMemory = true; objCompilerParameters.GenerateInMemory = true;
CompilerResults cr = compiler.CompileAssemblyFromSource(objCompilerParameters, cscode); CompilerResults cr = compiler.CompileAssemblyFromSource(objCompilerParameters, cscode);
if (cr.Errors.Count > 0) if (cr.Errors.Count > 0)
throw new Exception(cr.Errors[0].ErrorText); throw new Exception(cr.Errors[0].ErrorText);
return cr.CompiledAssembly; return cr.CompiledAssembly;
} }
} }
#endif #endif
} }