StructureMap em VB Net (WebForms)
-
05-07-2019 - |
Pergunta
Eu estou no processo de tentar ligar StructureMap para uma aplicação webforms existente. Desde que é webforms Eu tenho que usar injeção Setter, o que não é o ideal, mas é melhor que nada.
Onde eu estou vindo unstuck está traduzindo para VB (eu sou realmente um C # dev atualmente trabalhando em uma loja VB). Eu escrevi um scanner personalizado, que funciona bem em C #, mas estou completamente preso em como proceder para traduzi-lo em VB.
o original C # esta aparência:
public void Process(Type type, PluginGraph graph)
{
if (type.IsInterface)
{
graph.Configure(x => x.SetAllProperties(
y => y.TypeMatches(
z => z == type)));
}
}
O mais próximo que pode entrar em VB é o seguinte:
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
Eu estava esperando que refletor seria capaz de me ajudar, mas que vem com código que é semelhante ao meu, que também não vai compilação.
Então, qual é a tradução?
Solução
sim em VB.Net 9,0 este será grande problema.
Algo feio assim.
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
ou você pode esperar para VB.Net 10, onde será muito eassier.