2

I'm using CodeDom compiler to dynamically compile user defined scripts. We're working with C# scripts as standard, but I was wondering if there was a way how to support all CLI languages. To do that I'd have to detect used CLI language that was used in this particular source code.

Is there some elegant way how to detect only CLI languages from the source code?

Thanks

Biggles
  • 1,306
  • 1
  • 12
  • 22
  • 2
    There are an awful lot of CLI languages. http://en.wikipedia.org/wiki/List_of_CLI_languages – SLaks Feb 12 '13 at 21:22
  • 1
    Why do you have to detect it from the source code, rather than getting this information from somewhere else? This really is nothing I'd let a program guess. –  Feb 12 '13 at 21:30
  • 1
    Sure, getting this information is of course an option. I was just wondering if there's some hidden .NET functionality I've never heard of. I think it is reasonable to restrict the languages to only the ones supported by CodeDOM (C#, Visual Basic, C++, J#, and JScript). – Biggles Feb 12 '13 at 21:35
  • possible duplicate of [Detecting programming language from a snippet](http://stackoverflow.com/questions/475033/detecting-programming-language-from-a-snippet) – Ben Voigt Feb 12 '13 at 22:40
  • @user436730: "only CLI languages" and "only languages support by CodeDOM" are two extremely different (though overlapping) sets of languages. Which one are you actually looking for? – O. R. Mapper Feb 12 '13 at 22:44

1 Answers1

0

There are only 3 languages for which the framework provides a CodeDomProvider: C#, JScript and VB. Therefore, if the framework provides any direct method to parse "any language", it can only support these 3 languages. I don't think it does.

You may want to try to parse your code with all three implementations of CodeDomProvider, and keep the first that succeeds. It will take a dozen of lines of code.

I think it might be your best try.

Documentation for CodeDomProvider: http://msdn.microsoft.com/en-us/library/ds075xdx.aspx Documentation for CodeDomProvider.Parse: http://msdn.microsoft.com/en-us/library/system.codedom.compiler.codedomprovider.parse%28v=vs.110%29.aspx

Laurent LA RIZZA
  • 2,905
  • 1
  • 23
  • 41