c# - How to enable implicit line continuation in VBCodeProvider? -
the following vb.net code works when compiled visual studio:
sub main() dim source dictionary(of string, integer) = new dictionary(of string, integer) dim result = in source string.isnullorempty(i.key) select i.value end sub however, when trying compile using codedom appears not use implicit line continuation (i can make work putting underscores that's want avoid).
the code used:
static void main(string[] args) { string vbsource = @" imports system imports system.collections.generic imports system.linq module module1 sub main() dim source dictionary(of string, integer) = new dictionary(of string, integer) dim result = in source string.isnullorempty(i.key) select i.value end sub end module "; var provideroptions = new dictionary<string, string>(); provideroptions.add("compilerversion", "v3.5"); // .net v3.5 codedomprovider codeprovider = new microsoft.visualbasic.vbcodeprovider(provideroptions); compilerparameters parameters = new compilerparameters(); parameters.generateinmemory = true; parameters.referencedassemblies.add("system.core.dll"); compilerresults results = codeprovider.compileassemblyfromsource(parameters, vbsource); }
the problem telling use 3.5 version of compiler. implicit line-continuation not added feature until version 4.0 of .net framework, you'll need use version 4.0 (or later) compiler if want implicit line-continuation work. try changing this:
provideroptions.add("compilerversion", "v3.5"); // .net v3.5 to this:
provideroptions.add("compilerversion", "v4.0"); // .net v4.0
Comments
Post a Comment