I had this idea: create a program that simulates the visual studio to help people learn c#. It would be something like that “try for yourself” feature of w3schools.com
There would be a textbox that the user could put some code in it for example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
}
}
but now there’s the tricky part: if the user commited a synthax error for example, i’d like to show the error like the visual studio, or when the user clicks on a “verify” button, if the code is wrong, i’d get the same error as the visual studio would show up. Is it possible?
I think it is possible but you have to use reflection. With that you can dynamically create C# code which you can compile runtime. It is however quite advanced but as far as I know it is possible.
The following link might be useful:
Generating DLL assembly dynamically at run time
What you really want is:
What are the benefits of Compiler as a Service
But afaik this is not available now. Also you do not get the debugging functionality.
You can probably run a new instance of VS with debugging etc, but it might be a little overkill.