0

我正在尝试将 StructureMap 挂接到现有的 webforms 应用程序中。由于它是网络表单,我必须使用 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

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

那么,翻译是什么?

4

1 回答 1

0

是的,在 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,它会更容易。

于 2009-10-21T14:36:03.900 回答