可以用.net提供的动态编译来实现using System.IO;
using System.Reflection;
using System.Text;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Configuration;
using System.Data;
using System.Collections;private string ComplieDll(string strSource,string function,string paraName,string paraStruct)
{
StringBuilder _SB = new StringBuilder();
foreach (string str in arrRefNameSpace)
{
_SB.Append("using " + str+ ";\r\n");
} _SB.Append("using System;   \r\n");
_SB.Append("using System.Collections ;   \r\n");
_SB.Append("using System.Threading;   \r\n");
_SB.Append("using System.IO;  \r\n");
_SB.Append("using System.Text;   \r\n");
_SB.Append("using System.Data;  \r\n");
_SB.Append("using myPalauSqlHelp;    \r\n");


//namespace开始
_SB.Append("namespace CodeCompile   \r\n");
_SB.Append("{   \r\n");
_SB.Append("public class RunExpression : IRunExpression  \r\n");
_SB.Append("{   \r\n");
_SB.Append("public RunExpression()  \r\n");
_SB.Append("{   \r\n");
_SB.Append("}   \r\n");

_SB.Append(strSource); _SB.Append("public ISQLEntity getSqlEntity()  \r\n");
_SB.Append("{   \r\n");
_SB.Append(paraStruct);
_SB.Append("return ");
_SB.Append(function);
_SB.Append("(" + paraName + ");");
_SB.Append("}}}   \r\n"); string CodeContent = _SB.ToString();
CSharpCodeProvider _SCP = new CSharpCodeProvider();
CompilerParameters _CP = new CompilerParameters(); _CP.GenerateExecutable = false;
_CP.MainClass = "CodeCompile.RunExpression"; _CP.OutputAssembly = FileName;
_CP.IncludeDebugInformation = true; _CP.ReferencedAssemblies.Add( "System.dll" );
_CP.ReferencedAssemblies.Add( "System.Data.dll" );
_CP.ReferencedAssemblies.Add( "System.Web.dll" );
_CP.ReferencedAssemblies.Add( "System.XML.dll" );
_CP.ReferencedAssemblies.Add( "BenQGuru.Palau.DAL.dll" );
_CP.ReferencedAssemblies.Add( "BenQGuru.Palau.DAL.SQLCenter.dll" );
_CP.ReferencedAssemblies.Add( "help.dll" ); foreach (string str in arrRefDll)
{
_CP.ReferencedAssemblies.Add(str);
}
_CP.GenerateInMemory = false; _CP.WarningLevel = 3; _CP.TreatWarningsAsErrors = false;
    
_CP.CompilerOptions = "/optimize";
_CP.TempFiles = new TempFileCollection(filePath+@"\temp",true); CompilerResults _CR = _SCP.CreateCompiler().CompileAssemblyFromSource(_CP,CodeContent); System.Collections.Specialized.StringCollection _SC = _CR.Output; CompilerErrorCollection _EC = _CR.Errors; string errorMsg = "";
if(_EC.Count > 0)
{
for(int i=0;i<_EC.Count;i++)
{
if(!_EC[i].IsWarning)
{
errorMsg += _EC[i].ErrorText + "\r\n";
}
} }

return errorMsg;
}