2008-09-25 83 views
2

爲什麼我無法在VB.NET中創建classinheritsSystem.IO.Directory?根據Lutz Roeder的說法,這是而不是宣稱爲NotInheritable爲什麼我不能繼承IO.Directory?

我想創建一個utility class,它將功能添加到Directory class。例如,我想添加一個Directory.Move函數。

請指教,我會送你六包。好吧,我不會告訴你任何事情,但是如果你今晚來到酒吧,我會勾住你,然後在游泳池中擊敗你。

+0

謝謝傑夫阿特伍德編輯我的職務,並添加VB.NET標籤。難怪你不能再寫博客了! – 2008-09-25 20:21:35

+0

哈哈,他改變了內容。我添加了標籤:) – 2008-09-25 20:53:11

回答

11

從.NET

namespace System.IO 
{ 
    // Summary: 
    //  Exposes static methods for creating, moving, and enumerating through directories 
    //  and subdirectories. This class cannot be inherited. 
    [ComVisible(true)] 
    public static class Directory 

不能繼承靜態類的元數據。

5

是否使用 C#3.0 VB.NET 2008 - 那麼如果使用DirectoryInfo類,你可以添加一個Extension Method

+0

考慮到他指定了VB.NET,我打賭他沒有使用C#... – CodeRedick 2008-09-25 20:19:19

1

,你將有機會獲得一個通過MoveTo功能。

編輯:我會糾正自己...靜態目錄類已經有一個移動方法。

0

我猜測Reflector沒有爲VB正確拾取密封屬性(或者只是沒有正確顯示它)。如果你看一下IL,它是密封:

類公共抽象汽車ANSI 密封 beforefieldinit目錄