Documentation > Administrator Documentation > Setup Tutorial
Previous: Administrator Documentation
Next: Features
While each step will be broken down and explained, note that this document will cover the C# Interpreter’s use in Microsoft Visual Studio 2017. Steps may vary in other programming environments, or even other versions. If this is the case, find a dedicated tutorial online that explains the steps provided in this document, and watch for new or skipped steps.
The tutorials given will add on to each other until a complete and functional program is made. The purpose is to explain the code line by line to give important details on setup in the order that they are needed. The full code example can be found in Example.cs.
Download the Interpreter dll from here. Unzip and it is recommended to place the .dll, .xml, and License.txt in your project directory for organization.
In this tutorial, the Console App (.Net Framework) will be used.
Create a new project in Visual Studio as File > New > Project. Select Console App in the list, name the project, change the directory appropriately, and press OK, as in Figure 1.
Note: target framework is .NET 4.6.1. If you would like it in another version, send a request to the author.
Make a reference to the Interpreter assembly. In the Solution Explorer, under InterpreterFromConsole (or the name of your project), right click on References > Add Reference, as in Figure 2.
Under Browse tab, click Browse, locate the dll, and click Add. Make sure Interpreter.dll is checked in the window and click OK, as in Figure 3.
Go to the file(s) that should access the Interpreter, in this tutorial Program.cs, and add a using reference at the top, as in Figure 4.
The Interpreter is now ready to run. Write the following code in the Main method.
static void Main(string[] args) {
// the code
string code = "1 + 1;";
// run the Interpreter, collect the return value
object obj = CInterpreter.run(code, null);
// if the return value is null, make it the word null
if(obj == null) obj = "null";
// write the value to the console
Console.WriteLine("Returned value was: " + obj);
// wait for user
Console.ReadKey();
}
Press Start; green arrow on toolbar, Debug > Start Debugging, or F5. A window should appear that looks like Figure 5, then press any key to exit the application.
Note: The simplest version would be to run just the second line with a string literal, e.g. CInterpreter.run("1 + 1;", null);
Next, modify the code input. Change the first line to be:
// the code
Console.WriteLine("Enter code below...");
string code = Console.ReadLine();
// run ...
Start the program. Try a math expression to see that it is working, as in Figure 6.
Now that you have a working program, there are some additional features that can be used. The next page shows how to add them to this example.
Next: Features