public Interpreter()
{
this.varTable = new HashtableWithItemGetterHook(this);
AddNamespace("System");
AddNamespace("System.Collections");
AddReference("System.dll"); // Also works on Mono
SetValue("interpreter", this);
SetValue("_", this);
Utils.interpreter = this;
string fullExecutablePath = FullExecutablePath();
if (File.Exists(fullExecutablePath))
{
AddReference(fullExecutablePath);
}
string localNamespace = typeof(Interpreter).Namespace;
if (!string.IsNullOrEmpty(localNamespace))
{
AddNamespace(localNamespace);
}
ConstructorInfo constructorInfo = typeof(CSharpCodeProvider).GetConstructor(
new Type[] { typeof(System.Collections.Generic.Dictionary<string, string>) });
if (constructorInfo == null)
{
prov = new CSharpCodeProvider();
}
else
{
System.Collections.Generic.Dictionary<string, string> providerOptions =
new System.Collections.Generic.Dictionary<string, string>();
providerOptions.Add(
"CompilerVersion",
(Environment.Version < new Version("4.0.0.0")) ? "v3.5" : "v4.0");
prov = (CSharpCodeProvider)constructorInfo.Invoke(new object[] { providerOptions });
}
using (StringWriter stringWriter = new StringWriter())
{
gen = prov.CreateGenerator(stringWriter);
}
}