次の行を C# から VB.Net に変換すると、
式は値を生成しません
C#
query.ToList().ForEach(ti => cat.Add(ti));
VB.NET
query.ToList().ForEach(Function(ti) cat.Add(ti))
C# コード:
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
new DesignerMetadata().Register();
var toolbox = new ToolboxControl();
var cat = new ToolboxCategory("Standard Activities");
var assemblies = new List<Assembly>();
assemblies.Add(typeof(Send).Assembly);
assemblies.Add(typeof(Delay).Assembly);
assemblies.Add(typeof(ReceiveAndSendReplyFactory).Assembly);
var query = from asm in assemblies
from type in asm.GetTypes()
where type.IsPublic &&
!type.IsNested &&
!type.IsAbstract &&
!type.ContainsGenericParameters &&
(typeof(Activity).IsAssignableFrom(type) ||
typeof(IActivityTemplateFactory).IsAssignableFrom(type))
orderby type.Name
select new ToolboxItemWrapper(type);
query.ToList().ForEach(ti => cat.Add(ti));
toolbox.Categories.Add(cat);
Grid.SetColumn(toolbox, 0);
Grid.SetRow(toolbox, 1);
LayoutGrid.Children.Add(toolbox);
}
Vb.net に変換したい。vb.net でこのコードを変換すると、query.ToList().ForEach(Function(ti) cat.Add(ti)) でエラーが発生します。この行 .error is Expression は値を生成しません。
変換された VB.NET コード
Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim metadata = New DesignerMetadata()
metadata.Register()
'Create the ToolBoxControl
Dim toolbox = New ToolboxControl()
'Create a collection of category items
Dim cat = New ToolboxCategory("Standard Activities")
Dim assemblies = New List(Of Assembly)()
assemblies.Add(GetType(SendAndReceiveReplyFactory).Assembly)
assemblies.Add(GetType(Delay).Assembly)
assemblies.Add(GetType(ReceiveAndSendReplyFactory).Assembly)
Dim query = _
From asm In assemblies
From type In asm.GetTypes() _
Where type.IsPublic AndAlso Not type.IsNested AndAlso Not type.IsAbstract AndAlso Not type.ContainsGenericParameters AndAlso (GetType(Activity).IsAssignableFrom(type) OrElse GetType(IActivityTemplateFactory).IsAssignableFrom(type)) _
Order By type.Name
Select New ToolboxItemWrapper(type)
query.ToList().ForEach(Function(ti) cat.Add(ti))
toolbox.Categories.Add(cat)
Grid.SetColumn(toolbox, 0)
Grid.SetRow(toolbox, 1)
LayoutGrid.Children.Add(toolbox)
End Sub