Validate C# syntax with C#
See the question and my original answer on StackOverflowYou'll have to cookup some compilable C# code (using CodeDom or just adding manual snippets around what your users will manually code), and then compile it, as described here: How to programmatically compile code using C# compiler