【问题标题】:Structuremap in VB .Net (WebForms)VB .Net(WebForms)中的结构图
【发布时间】:2010-12-08 17:27:02
【问题描述】:

我正在尝试将 StructureMap 连接到现有的网络表单应用程序。 由于是 web 表单,我必须使用 Setter Injection,这并不理想,但总比没有好。

我要解决的问题是翻译成 VB(我真的是一名 C# 开发人员,目前在一家 VB 商店工作)。我编写了一个自定义扫描仪,它在 C# 中运行良好,但我完全不知道如何将它翻译成 VB。

原来的 C# 是这样的:

public void Process(Type type, PluginGraph graph)
{
    if (type.IsInterface)
    {
        graph.Configure(x => x.SetAllProperties(
                y => y.TypeMatches(
                    z => z == type)));
    }
}

我能在 VB 中得到的最接近的是:

Public Sub Process(ByVal type As Type, ByVal graph As PluginGraph) Implements ITypeScanner.Process

    If type.IsInterface Then

        graph.Configure(Function(x) _
                            x.SetAllProperties(Function(y) _
                                y.TypeMatches(Function(z) _
                                    return z Is type _
                                ) _
                            ) _
                        )

    End If

End Sub

我希望反射器能够帮助我,但它提供的代码与我的相似,也无法编译。

那么,翻译是什么?

【问题讨论】:

    标签: vb.net structuremap ioc-container webforms


    【解决方案1】:

    是的,在 VB.Net 9.0 中这将是一个大问题。

    像这样丑陋的东西。

    Private Sub configure(ByVal type As Type, ByVal graph As PluginGraph)
                If type.IsInterface Then
                    graph.Configure(Function(x) setproperties(x, type))
                End If
            End Sub
    
            Private Function setproperties(ByVal x As Registry, ByVal type As Type) As Boolean
                x.SetAllProperties(Function(y) setTypeMatches(y, type))
                Return True
            End Function
    
            Private Function setTypeMatches(ByVal y As SetterConvention, ByVal type As Type) As Boolean
                y.TypeMatches(Function(z) returnType(z, type))
                Return True
            End Function
    
            Private Function returnType(ByVal z As Type, ByVal type As Type) As Boolean
                Return z Is type
            End Function
    

    或者您可以等待 VB.Net 10,它会更容易。

    【讨论】:

    • 这就是我的目标。嗯,再过几个月我就可以在办公室使用 VS2010。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多