Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can VFP be part of DotNet without loosing it's IDE?
Message
From
16/07/2003 02:59:48
 
 
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Miscellaneous
Thread ID:
00809892
Message ID:
00810549
Views:
24
Cool, Neil. Now we can say, "I can compile C# code from inside VFP". Has a nice ring to it. :-)

>David,
>
>Problem solved ;-) the VFP community can now generate .NET framework executables from VFP's IDE. Compile the following class library for use from VFP through the interop layer.
>
>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!
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Previous
Reply
Map
View

Click here to load this message in the networking platform