Aşağıdaki, oldukça standart bir kod CSharpCodeProvider
civarında bir sarıcı olarak var. Bu sınıf çok iyi çalışıyor ve gayet iyi çalışıyor, vb. Ancak, uygulamamın .NET 3.5'e göre oluşturulmuş olmasına ve bu derlemeyi yaparken v3.5 derlemelerine atıfta bulunmasına rağmen, yine de lambda veya otomatik özellikleri gibi ekstra güzel C# 3.5 sözdizimi. Bu çalışmanın bir yolu var mı?CSharpCodeProvider .NET 2.0'da sıkışmış gibi görünüyor, nasıl yeni özellikler edinebilirim?
Bu sınıfın sadece güvenlik duvarım tarafından onaylanacağı anlaşılan bir fikir olan csc.exe
adlı sargının sarıldığı izlenimi altındaydım (uygulamam csc.exe
erişimini dener). Belki de options.CompilerOptions
'u bir şeye ayarlamalıyım?
protected virtual void Compile()
{
Microsoft.CSharp.CSharpCodeProvider csProvider = new Microsoft.CSharp.CSharpCodeProvider();
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = false;
options.GenerateInMemory = true;
options.IncludeDebugInformation = true;
foreach (string s in this.ReferencedAssemblies)
{
options.ReferencedAssemblies.Add(s);
}
CompilerResults result;
string source = this.CodeTemplate;
// [snip] Do some manipulation to fill in the template with values.
result = csProvider.CompileAssemblyFromSource(options, source);
this.HasErrors = result.Errors.HasErrors;
this.Errors = new CompilerError[result.Errors.Count];
result.Errors.CopyTo(Errors, 0);
if (HasErrors && ThrowOnErrors)
throw new InvalidProgramException("The code currently stored in the " + this.GetType() + " cannot be compiled.");
else if (HasErrors)
return;
this.CompiledAssembly = result.CompiledAssembly;
}
DÜZENLEME:
Ben mscorlib
, System.Core
, System.Text
ve şu anda kendi meclislerinin birine referanslara sahip.
3.5 2.0 Framework üzerine kuruludur. –