2009-08-26 92 views
1

我試圖讓this sitemap clas工作。VB.NET和LINQ。我在這裏錯過了什麼?

它似乎使用LINQ,我從來沒有用過,但編程的一半樂趣是學習新東西!

我的問題是,我得到LINQ代碼的編譯錯誤。 VS只是不認識它。我有一個參考system.data.linq,我有一個進口system.data.linq,但仍然在代碼讀取,「Dim folders = From o在Directory.GetDirectories ...」,它告訴我「預計結束聲明。」

我在配線這件東西時缺少什麼,以便我可以使用LINQ?我的框架是2.0.5。 LINQ在2中對我來說簡直不可用?如果是這樣,爲什麼我的GAC中的system.data.linq?

下面的代碼:

Private Sub AddFolders(ByVal parentNode As SiteMapNode) 
Dim folders = From o In Directory.GetDirectories(HttpContext.Current.Server.MapPath(parentNode.Key)) _ 
Let dir = New DirectoryInfo(o) _ 
Where Not Regex.Match(dir.Name, ExcludedFolders).Success _ 
Select New() 

     For Each item In folders 
      Dim folderUrl As String = parentNode.Key + item.DirectoryName 
      Dim folderNode As New SiteMapNode(Me, folderUrl, Nothing, item.DirectoryName, item.DirectoryName) 

      AddNode(folderNode, parentNode) 
      AddFiles(folderNode) 
     Next 
    End Sub 

感謝你們。堆棧溢出岩石。

+0

Arg。我們仍然在2005年。我每週都會對它們進行竊聽,我們需要升級並被忽略。至少,這對我來說是更多的彈藥。 謝謝你們! – aape 2009-08-26 12:53:48

回答

3
Dim folders = From o In Directory.GetDirectories(HttpContext.Current.Server.MapPath(parentNode.Key)) _ 
Let dir = New DirectoryInfo(o) _ 
Where Not Regex.Match(dir.Name, ExcludedFolders).Success _ 
Select dir 

編輯:其實你不能在.NET 2.0中使用LINQ的,至少在沒有一些調整。不過,使用LINQ和與.NET 3.5編譯器編譯後的代碼可以在運行。 NET 2.0運行時,使用LinqBridge

+0

非常感謝。 LinqBridge看起來很漂亮。 – aape 2009-08-26 13:00:02

2

您必須定位3.5(Visual Studio 2008)以使用linq。

2

根據this link(我沒有親自測試),您可以使用LINQ和.NET 2.0。你需要Visual Studio 2008 ...

如果完全有可能,我建議你升級到.NET 3.5,除非你想等待即將發佈的.NET 4.0 :-)

+0

感謝您的信息和鏈接。 – aape 2009-08-26 12:59:24

2

如果您的目標是.NET Framework 2,那麼您可以通過一點額外的努力來獲得LINQ的工作。

最簡單的方法把事情快速移動是下載LINQBridge它提供了一個LINQ實施框架2.

至於爲什麼你在GAC看到System.Data.Linq程序...聽起來像你.NET 3.5與.NET 2.0並排安裝

+0

「...聽起來像你有NET 3.5與.NET 2.0並排安裝」 謝謝。那會讓我一整天都在想這些。 – aape 2009-08-26 13:01:15

相關問題