I have some user inputs of type string[] for calculations. I want to compile them and get faster computation than any other method.
User input strings:
double _1 = 2 + 2;
double _2 = _1 + Get_Variable("var1");
return _2;
I convert the input to strings which are suitable for generating a dll
namespace namespace_Calculator
{
public class Class_Calculator
{
public static double Start_Calculating()
{
//user defined string[] type calculation inputs
double _1 = 2 + 2;
double _2 = _1 + Get_Variable("var1");
return _2;
//user defined string[] type calculation inputs
}
}
}
How can I return the Get_Variable() function from main exe?
I'm currently using DataTable().Compute()
I can call Start_Calculating() and get result without variables.
object[] p = new object[] { };
Assembly yeni = AppDomain.CurrentDomain.Load(File.ReadAllBytes(Dll_location));
Type t = yeni.GetType("namespace_Calculator.Class_Calculator");
MethodInfo mi = t.GetMethod("Start_Calculating");
object ins = Activator.CreateInstance(t);
double cevap = (double)mi.Invoke(ins, p);
Thanks in advance.
The solution is easier than it seems.
It is enough to add "Name.exe" to CompilerParameters.ReferencedAssemblies object.
Create a standart static public function
Nothing special