2010-07-07 81 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