Possible Duplicate:
C# eval equivalent?
Is it possible to Execute a C# command that is stored in a string variable
a thing like Dynamic query in SqlServer
Possible Duplicate:
C# eval equivalent?
Is it possible to Execute a C# command that is stored in a string variable
a thing like Dynamic query in SqlServer
There is nothing built into the current version of .NET that allows this. However the Roslyn project aims to specifically enable scenarios like this. They have a CTP out.
A simple example, (from Kirill Osenkov's blog), is:
[TestMethod]
public void SimpleEvaluationUsingScriptEngine()
{
ScriptEngine engine = new ScriptEngine();
int result = engine.Execute<int>("1 + 2");
Assert.AreEqual(3, result);
}
You can use CSharpCodeProvider to compile source code from a file or from strings into an assembly you can load. Then you can invoke the generated classes via reflexion.