次の VB.NET コードは、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
ただし、それを使用してコンパイルしようとすると、CodeDom
暗黙的な行継続を使用しないように見えます (アンダースコアを入れることで機能させることができますが、それはまさに避けたいことです)。
使用したコード:
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);
}