2011-12-01 4 views
1

へのC#のコードを変換する私は はVB.NET

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:

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コードでインラインに配置):

正しい変換は何ですか?

答えて

3

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  
0

ソースコードが

+0

+1リンクありがとうございます! –

+0

あなたのマシン上で実行できるように、機能を含むSharpDevelopをダウンロードしてください。 – CodingBarfield

+0

ほぼ4年後、出力はまだ間違っています。 –

0

を変換するために、このWebページdeveloperfusionを試してみてください私はを通して、あなたのコードブロックを実行して、何のコンパイルエラーを取得していないことができたtelerik's converterをお勧めします。

+0

ほぼ4年後、出力はまだ間違っています。 –

+0

@DaveDoknjasは4年前に正解したかもしれないが、今あなたが望むことをしないかもしれない答えを投票するのはむしろ失礼だと思われる。 – Gent

+0

telerikコンバーターを盲目的に接続する場合は、ガベージが生成されないことを確認する必要があります。これは完全に不当な 'Key'キーワードを追加しますが、それでも追加します。 。このコンバータのコーダは、さまざまなタイプのイニシャライザの違いを理解していません。 –