Javascript has an eval function that can dynamically execute code. But not in C!
The following code is the core code extracted from my project. In fact, it is very simple to compile --> Generate an assembly --> reflection call.
Learn from beginners!
// If execution is successful, null is returned; otherwise, error text is returned.
String strerr;
// The code execution result is returned in the form of a string, because only the string result is required in my project, you can follow the instructions to modify it yourself. Www.elivn.com
String strresult = commanddebugger. evaluator. eval ("Your codes", out strerr );
Download Code:
------------------------------------------------------------------
Thank you for your comments. I am new to you. Please forgive me. In fact, this function is tailored according to my program.
Ironpython has heard of it, but it has never been used and is not familiar with it.
In my project, there is such a function that can dynamically execute a piece of code and return a value.
For example, to view the value of a static variable in the current context, you can write it as follows:
String strerr;
String strresult = commanddebugger. evaluator. eval ("staticclass. Value", out strerr );
You can also use include C:/Windows/system. dll and other statements to import the assembly.
Using system. xml;
Print: Output statement results ..
If it is simply to implement an eval function, I think this method is certainly not very good, but according to the requirements of my program, haha, it should be a good deal... Please kindly advise !!
The following classes are mainly used for implementation.
Csharpcodeprovider
Compilerparameters
Compilerresults
Javascript has an eval function that can dynamically execute code. But not in C!
The following code is the core code extracted from my project. In fact, it is very simple to compile --> Generate an assembly --> reflection call.
Learn from beginners!
// If execution is successful, null is returned; otherwise, error text is returned.
String strerr;
// The code execution result is returned in the form of a string, because only the string result is required in my project, you can follow the instructions to modify it yourself. Www.elivn.com
String strresult = commanddebugger. evaluator. eval ("Your codes", out strerr );
Download Code:
------------------------------------------------------------------
Thank you for your comments. I am new to you. Please forgive me. In fact, this function is tailored according to my program.
Ironpython has heard of it, but it has never been used and is not familiar with it.
In my project, there is such a function that can dynamically execute a piece of code and return a value.
For example, to view the value of a static variable in the current context, you can write it as follows:
String strerr;
String strresult = commanddebugger. evaluator. eval ("staticclass. Value", out strerr );
You can also use include C:/Windows/system. dll and other statements to import the assembly.
Using system. xml;
Print: Output statement results ..
If it is simply to implement an eval function, I think this method is certainly not very good, but according to the requirements of my program, haha, it should be a good deal... Please kindly advise !!
The following classes are mainly used for implementation.
Csharpcodeprovider
Compilerparameters
Compilerresults