Project Description
SharpScriptLib is a library for compiling C#(CSharp) code in runtime and running in a new Application Domain or Invoking a method.

Support:
1) Full C# Code compilation
2) Running CIL Assemblies in a new Application Domain with arguments
3) Invoking Methods from CIL Assemblies with parameters

A SAMPLE APPLICATION

using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;
using System.Reflection;
using SharpScriptLib;
namespace SharpScriptLibDemo1
{
class Program
{
static void Main(string[] args)
{
// create a sample console application
string Source = "using System;\n namespace demo{class demo{ static public void Main(){ Console.Read();}}}";
// Create the compiler parameters
CompilerParameters Params = new CompilerParameters();
Params.CompilerOptions = "/t:exe";
Params.GenerateExecutable = true;
Params.OutputAssembly = "demo.exe";
Params.ReferencedAssemblies.Add("System.dll");
try
{
// Compile the code
Assembly asm = SharpScriptLib.SharpScriptLib.CompileFromSource(Params, new string[] { Source });
// run the application in a new application
SharpScriptLib.SharpScriptLib.Run("Demo", "demo.exe", new string[] { });
// invoke Main Method
SharpScriptLib.SharpScriptLib.InvokeMethod(asm, "demo.demo", "Main", new object[] { });
}
catch (Exception ex)
{
Console.WriteLine("ERROR");
Console.WriteLine(ex.Message);
}
}
}
}

Last edited Sep 5, 2008 at 11:23 AM by herculesthemad, version 4