2010-07-07 54 views
1

我在C#中发现了4或5个“小写路由”的例子,但是当我使用telerik代码转换器时,出现了一堆错误。ASP.NET MVC2小写Visual Basic中的路由

即是与"extension methods can be defined only in modules."

有没有人对如何映射航线VB为小写任何好的资源?

编辑:

这里是一些示例转换被示数

Imports System 
Imports System.Web.Mvc 
Imports System.Web.Routing 

Namespace MyMvcApplication.App.Helpers 
    Public Class LowercaseRoute 
     Inherits System.Web.Routing.Route 
     Public Sub New(ByVal url As String, ByVal routeHandler As IRouteHandler) 
      MyBase.New(url, routeHandler) 
     End Sub 
     Public Sub New(ByVal url As String, ByVal defaults As RouteValueDictionary, ByVal routeHandler As IRouteHandler) 
      MyBase.New(url, defaults, routeHandler) 
     End Sub 
     Public Sub New(ByVal url As String, ByVal defaults As RouteValueDictionary, ByVal constraints As RouteValueDictionary, ByVal routeHandler As IRouteHandler) 
      MyBase.New(url, defaults, constraints, routeHandler) 
     End Sub 
     Public Sub New(ByVal url As String, ByVal defaults As RouteValueDictionary, ByVal constraints As RouteValueDictionary, ByVal dataTokens As RouteValueDictionary, ByVal routeHandler As IRouteHandler) 
      MyBase.New(url, defaults, constraints, dataTokens, routeHandler) 
     End Sub 

     Public Overrides Function GetVirtualPath(ByVal requestContext As RequestContext, ByVal values As RouteValueDictionary) As VirtualPathData 
      Dim path As VirtualPathData = MyBase.GetVirtualPath(requestContext, values) 

      If path IsNot Nothing Then 
       path.VirtualPath = path.VirtualPath.ToLowerInvariant() 
      End If 

      Return path 
     End Function 
    End Class 

    Public NotInheritable Class RouteCollectionExtensions 
     Private Sub New() 
     End Sub 
     <System.Runtime.CompilerServices.Extension()> _ 
     Public Shared Sub MapRouteLowercase(ByVal routes As RouteCollection, ByVal name As String, ByVal url As String, ByVal defaults As Object) 
      routes.MapRouteLowercase(name, url, defaults, Nothing) 
     End Sub 

     <System.Runtime.CompilerServices.Extension()> _ 
     Public Shared Sub MapRouteLowercase(ByVal routes As RouteCollection, ByVal name As String, ByVal url As String, ByVal defaults As Object, ByVal constraints As Object) 
      If routes Is Nothing Then 
       Throw New ArgumentNullException("routes") 
      End If 

      If url Is Nothing Then 
       Throw New ArgumentNullException("url") 
      End If 

      Dim route = New LowercaseRoute(url, New MvcRouteHandler()) With { _ 
      .Defaults = New RouteValueDictionary(defaults), _ 
      .Constraints = New RouteValueDictionary(constraints) _ 
      } 

      If [String].IsNullOrEmpty(name) Then 
       routes.Add(route) 
      Else 
       routes.Add(name, route) 
      End If 
     End Sub 
    End Class 
End Namespace 

回答

1

为了解决代码“扩展方法只能在模块中定义。”问题: 将您定义这些方法的“NotInheritable类”更改为“Module”并删除构造函数。

+0

笨我......已经迟到了......我正试图改变SUB而不是CLASS。感谢您的帮助。 – 2010-07-08 16:08:47