如何将C#StructureMap初始化转换为VB.NET?

时间:2008-12-14 19:09:38

标签: c# vb.net structuremap

我准备通过这个滑动玻璃门。我无法弄清楚如何在VB.NET中执行以下代码来挽救我的生命。

private static void InitStructureMap()
    {
        ObjectFactory.Initialize(x =>
                                     {
                                         x.AddRegistry(new DataAccessRegistry());
                                         x.AddRegistry(new CoreRegistry());
                                         x.AddRegistry(new WebUIRegistry());

                                         x.Scan(scanner =>
                                                    {
                                                        scanner.Assembly("RPMWare.Core");
                                                        scanner.Assembly("RPMWare.Core.DataAccess");
                                                        scanner.WithDefaultConventions();
                                                    });
                                     });
    }

4 个答案:

答案 0 :(得分:9)

目前,这根本不可能。当前版本的VB不支持多行(或语句)lambda。每个lambda只能包含一个表达式。 VB的下一个版本将解决这个问题(在上一个版本中没有足够的时间)。

与此同时,你必须与代表合作:

Private Shared Sub Foobar(x As IInitializationExpression)
    x.AddRegistry(New DataAccessRegistry)
    x.AddRegistry(New CoreRegistry)
    x.AddRegistry(New WebUIRegistry)
    x.Scan(AddressOf Barfoo)
End Sub

Private Shared Sub Barfoo(ByVal scanner As IAssemblyScanner) 
    scanner.Assembly("RPMWare.Core")
    scanner.Assembly("RPMWare.Core.DataAccess")
    scanner.WithDefaultConventions
End Sub

' … '
ObjectFactory.Initialize(AddressOf Foobar)

答案 1 :(得分:2)

答案 2 :(得分:1)

我的VB.NET没有达到标准,所以我无法直接帮助您处理代码。然而,我可以告诉你的是如何自己做,这是一个很糟糕的事情。基本上,您需要使用Reflector来读取包含此代码的可执行文件 - 然后您可以选择将其输出为VB.NET - 这有多酷,并且这种技巧可以双向运行。

答案 3 :(得分:0)

这很棒,无论出于何种原因,它都不会编译。啊。

以下是它的结果:

Private Shared Sub InitStructureMap()
ObjectFactory.Initialize(Function (ByVal x As IInitializationExpression) 
    x.AddRegistry(New DataAccessRegistry)
    x.AddRegistry(New CoreRegistry)
    x.AddRegistry(New WebUIRegistry)
    x.Scan(Function (ByVal scanner As IAssemblyScanner) 
        scanner.Assembly("RPMWare.Core")
        scanner.Assembly("RPMWare.Core.DataAccess")
        scanner.WithDefaultConventions
    End Function)
End Function)
End Sub

我尝试添加_使其成为一行(也不起作用)

 Private Shared Sub InitStructureMap()
ObjectFactory.Initialize(Function (ByVal x As IInitializationExpression) _
    x.AddRegistry(New DataAccessRegistry) _
    x.AddRegistry(New CoreRegistry) _
    x.AddRegistry(New WebUIRegistry) _
    x.Scan(Function (ByVal scanner As IAssemblyScanner) _
    scanner.Assembly("RPMWare.Core") _
    scanner.Assembly("RPMWare.Core.DataAccess") _
    scanner.WithDefaultConventions() _
    End Function) _
End Function) 
End Sub

其他人讨厌他们的遗留应用吗? :P