0

我正在尝试查看控制器类名称是否是传入的控制器名称的名称。我认为我的 lambda 表达式是错误的,这就是它无法正常工作的原因。我传入了正确的控制器名称,但导出变量始终为空。

  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()

如果您需要我澄清任何事情,请告诉我!谢谢!

4

1 回答 1

1

是的,你的 lambda 表达式是错误的,这应该可以解决问题

Dim export As Lazy(Of IController) = Me.container.GetExports(Of IController)() _
                                              .Where(Function(c) c.Value.GetType.Name = controllerClassName) _
                                              .FirstOrDefault() 
于 2012-06-22T13:45:19.610 回答