我试图查看控制器类名是否是传入的控制器名称的名称。我认为我的lambda表达式是错误的,这就是它无法正常工作的原因。我传入正确的控制器名称,但导出变量始终为null。
Public Function CreateController(requestContext As System.Web.Routing.RequestContext,
controllerName As String)
As System.Web.Mvc.IController Implements
System.Web.Mvc.IControllerFactory.CreateController
Dim controller As IController = Nothing
If controllerName IsNot Nothing Then
Dim controllerClassName As String = controllerName & "Controller"
Dim export As Lazy(Of IController) = Me.container.GetExports(Of IController)().Where(
Function(c)
Return c.Value.GetType.Name = controllerClassName
End Function
).FirstOrDefault()
如果您需要我澄清任何事情,请告诉我!谢谢!
答案 0 :(得分:1)
是的,你的lambda表达式是错误的,这应该可以解决问题
Dim export As Lazy(Of IController) = Me.container.GetExports(Of IController)() _
.Where(Function(c) c.Value.GetType.Name = controllerClassName) _
.FirstOrDefault()