Structuremap في VB صافي (لدت WebForms)
-
05-07-2019 - |
سؤال
وأنا في عملية محاولة لربط StructureMap الدخول إلى تطبيق نماذج الويب الموجودة. لأنه في نماذج الويب لدي لاستخدام حقن واضعة، وهي ليست مثالية، لكنها أفضل من لا شيء.
وأين أنا قادم فاشل هو ترجمة ل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 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 حيث سيكون بكثير eassier.
لا تنتمي إلى StackOverflow