How to enable implicit line continuation in VBCodeProvider?

The following VB.NET code works when compiled from the Visual Studio:

Sub Main()
    Dim source As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)

    Dim result = From i In source
                 Where String.IsNullOrEmpty(i.Key)
                 Select i.Value

End Sub

However, when trying to compile it by using CodeDom it appears not use implicit line continuation (I can make it to work by putting underscores but that's exactly what I want to 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 As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)

        Dim result = From i In source
                     Where 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);
        }

Answers


The problem is that you are telling it to use the 3.5 version of the compiler. Implicit line-continuation was not added as a feature until version 4.0 of the .NET Framework, so you'll need to use the version 4.0 (or later) compiler if you want the implicit line-continuation to work. Try changing this:

providerOptions.Add("CompilerVersion", "v3.5"); // .NET v3.5

To this:

providerOptions.Add("CompilerVersion", "v4.0"); // .NET v4.0

Need Your Help

weka decision tree java

java weka decision-tree

I want to make a list of all the predictions.

An efficient database design for a simple forum using php and mysql

php mysql database optimization

I am in the process of designing a database for forum functionality for my website.After doing some searching on SO and google, I have come up with the following design:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.