I am designing a desktop application in C#, which automatically generates code
based on the requirement provided.
Now I want to check the syntax of the code that is generated.
In the earlier stages we can feed the system some possibilities.
Is there some thing i can do here rather than feeding the system for
every possibility?
Thanks.
Providing you generate the code yourself, the best way to ensure it’s syntactically correct is to generate a syntactically correct code at the first place.
Otherwise, besides creating a custom C# parser and semantic analyzer (a “half-compiler”), you can consider calling the command-line C# compiler, which is part of the .NET framework, and analyze its textual output.
The command-line C# compiler usage and output is described here in MSDN. Have a look on
Process.Starton how to start a new process from your code.