I need to have a textbox on a ASP.NET page in which a user would paste code and select one of the preset languages (C#, VB.NET, Python, Ruby etc) and I need to verify if the code compiles successfully. If it doesn't, then I need to show the errors and warnings with line numbers.
How do I go about doing this?
You'll need to host all sorts of compilers you'd like to support and use their APIs. If a compiler doesn't expose an API, you'd need to use System.Diagnostics.Process
to launch it and grab the output for parsing.
This is far from a trivial task though.
If you're confident you need this, ask yourself several questions.
And this is just the tip of the iceberg.
Answering your comment, yes, there is a compiler API for C# and VB .NET which is called CodeDOM .
There's plenty of information about it on the net. You may want to check out this question as well.
You may want to take a look at the Roslyn project (formerly Compiler as a Service) at http://msdn.microsoft.com/en-us/roslyn which was released yesterday. This is the new compiler APIs coming for C# and VB. It won't help for Python or Ruby but should do what you need for C# and VB once it ships (post Dev 11).
对于C#和VB,使用Roslyn CTP创建一个Compilation对象,然后调用GetDiagnostics()方法确定错误。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.