将代码从C#转换为VB.NET

我把它从C#翻译成了VB.NET

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:

  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 

但我得到一个错误(在VB.NET代码中内联):

正确的翻译是什么?

删除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