I have developed an application that uses c# script files for certain configurations and settings. The script file contains various user generated objects and certain functions on those objects. Presently, the user has to generate a .cs file using a third party editor and supply the path to my program to make use of it. The disadvantage with this method is that the user does not have the flexibility of Auto-complete and intellisense-esque support while editing the script files.
I want to embed the script editing part into my application. I can do that using a rich-text editor. But coding the auto-complete part is a huge pain. Is there any way in which I can provide the user with an in-program editor that also does auto-complete....
Code for compiling a script dynamically in a program.
public String Compile(String inputfilepath)
{
CompilerResults res = null;
CSharpCodeProvider provider = new CSharpCodeProvider();
String errors = "";
if (provider != null)
{
try
{
Assembly asb = Assembly.Load("BHEL.PUMPSDAS.Datatypes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=81d3de1e03a5907d");
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = false;
options.OutputAssembly = String.Format(outFileDir + oName);
options.GenerateInMemory = false;
options.TreatWarningsAsErrors = false;
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("System.Core.dll");
options.ReferencedAssemblies.Add("System.Xml.dll");
options.ReferencedAssemblies.Add("System.Xml.dll");
options.ReferencedAssemblies.Add(asb.Location);
res = provider.CompileAssemblyFromFile(options, inputfilepath);
errors = "";
if (res.Errors.HasErrors)
{
for (int i = 0; i < res.Errors.Count; i++)
{
errors += "\n " + i + ". " + res.Errors[i].ErrorText;
}
}
}
catch (Exception e)
{
throw (new Exception("Compilation Failed with Exception!\n" + e.Message +
"\n Compilation errors : \n" + errors + "\n"));
}
}
return errors;
}