views:

123

answers:

1

I'm in the process of trying to hook StructureMap in to an existing webforms application. Since it's webforms I have to use Setter Injection, which is not ideal, but it's better than nothing.

Where I'm coming unstuck is translating to VB (I'm really a C# dev currently working in a VB shop). I've written a custom scanner, which works fine in C#, but I'm completely stuck on how to go about translating it into VB.

the original C# looks like this:

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

The closest I can get in VB is this:

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

I was hoping that reflector would be able to help me out, but that comes up with code that is similar to mine, which also wont compile.

So, what's the translation?

A: 

yep in VB.Net 9.0 this will be big problem.

Something ugly like this.

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

or you can wait for VB.Net 10 where it will be much eassier.

chrissie1
That's what I was coming round to. Ah well only another few months till I can use VS2010 in the office.
ilivewithian