>using System; >using System.Runtime.InteropServices; >using System.CodeDom.Compiler; >using System.Reflection; >using Microsoft.CSharp; > > >namespace VFPInteropSample >{ > [ClassInterface(ClassInterfaceType.AutoDual)] > [ProgId("VFPInteropSample.Compile")] > public class Compile > { > public Compile() > { > } > > public int CompileScript(string SourceCode) > { > ICodeCompiler CSharpCompiler = new CSharpCodeProvider().CreateCompiler(); > CompilerParameters CompilerParams = new CompilerParameters(); > > CompilerParams.ReferencedAssemblies.Add("System.dll"); > CompilerParams.GenerateExecutable = true; > CompilerParams.GenerateInMemory = false; > CompilerParams.IncludeDebugInformation = false; > CompilerParams.OutputAssembly = "c:\\generatedcode.exe"; > > CompilerResults CompiledResults = CSharpCompiler.CompileAssemblyFromSource(CompilerParams, SourceCode); > > return(CompiledResults.Errors.Count); > } > } >} >>Now create the following (c:\source.cs) source file.
>using System; > >class Hello >{ > static void Main() > { > Console.WriteLine("Hello World!"); > } >} >>Now enter the following in VFP and voila! a ready to go C# compiler built using Microsoft Visual FoxPro technology <g>
>loCodeGenerator = CreateObject("VFPInteropSample.Compile") >lcSourceCode = filetostr("c:\test.cs") >? loCodeGenerator.CompileScript(lcSourceCode) >>It does need at least a weekends worth of work before we could call it production quality!