[英]translate code from C# to VB.NET
I translated this from C# to VB.NET 我将其从C#转换为VB.NET
C#: C#:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
var config = new HttpConfiguration() { EnableTestClient = true };
routes.Add(new ServiceRoute("api/contacts", new HttpServiceHostFactory() { Configuration = config }, typeof(ContactsApi)));
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
VB.NET: VB.NET:
Public Shared Sub RegisterRoutes(routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
Dim config = New HttpConfiguration() With { _
Key .EnableTestClient = True _
}
routes.Add(New ServiceRoute("api/contacts", New HttpServiceHostFactory() With { _
Key .Configuration = config _ <-----------Name of field or property being initialized in an object initializer must start with '.'.
}, GetType(ContactsApi)))
' Route name
' URL with parameters
' Parameter defaults
routes.MapRoute("Default", "{controller}/{action}/{id}", New With { _
Key .controller = "Home", _
Key .action = "Index", _
Key .id = UrlParameter.[Optional] _
})
End Sub
But I get an error (placed inline in VB.NET code): 但是我收到一个错误(在VB.NET代码中内联):
What would the correct translation? 什么会正确的翻译?
Remove the Key
. 拔下
Key
。
Public Shared Sub RegisterRoutes(routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
Dim config = New HttpConfiguration() With { _
.EnableTestClient = True _
}
routes.Add(New ServiceRoute("api/contacts", New HttpServiceHostFactory() With { _
.Configuration = config _ <-----------Name of field or property being initialized in an object initializer must start with '.'.
}, GetType(ContactsApi)))
' Route name
' URL with parameters
' Parameter defaults
routes.MapRoute("Default", "{controller}/{action}/{id}", New With { _
.controller = "Home", _
.action = "Index", _
.id = UrlParameter.[Optional] _
})
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.