为什么我不能继承IO.Directory?

发布于 2024-07-06 08:04:15 字数 356 浏览 6 评论 0原文

为什么我无法在 VB.NET 中创建一个继承 System.IO.Directory? 根据 Lutz Roeder 的说法,它没有被声明为NotInheritable

我想创建一个向 Directory 类添加功能的 实用程序类。 例如,我想添加一个 Directory.Move 函数。

请告知,我将寄给您六包。 好吧,没关系,我不会给你发任何东西,但如果你今晚来酒吧,我会把你勾搭起来,然后在台球上打败你。

Why can't I create a class in VB.NET that inherits System.IO.Directory? According to Lutz Roeder, it is not declared as NotInheritable!

I want to create a utility class that adds functionality to the Directory class. For instance, I want to add a Directory.Move function.

Please advise and I will send you a six pack. OK nevermind I'm not sending you anything but if you come to the bar tonight I will hook you up and then beat you in pool.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

筱武穆 2024-07-13 08:04:16

来自 .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

您不能从静态类继承。

From the Meta Data of .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

You cannot inherit from a Static Class.

未央 2024-07-13 08:04:16

您是否使用C# 3.0 VB.NET 2008 - 那么您可以添加扩展方法

Are you using C# 3.0 VB.NET 2008 -- then you could add an Extension Method

咽泪装欢 2024-07-13 08:04:16

如果您使用 DirectoryInfo 类,您将可以访问 MoveTo 函数。

编辑:我会纠正自己...静态 Directory 类已经有一个 Move 方法。

If you use the DirectoryInfo class, you will have access to a MoveTo function.

EDIT: I'll correct myself... The static Directory class already has a Move method.

江心雾 2024-07-13 08:04:16

我猜想 Reflector 没有正确获取 VB 的密封属性(或者可能只是没有正确显示它)。 如果你看一下 IL,它是密封的:

class public abstract auto ansi sealed beforefieldinit 目录

I'd guess that Reflector isn't picking up the sealed attribute correctly for VB (or perhaps just not displaying it properly). If you look at the IL, it is sealed:

class public abstract auto ansi sealed beforefieldinit Directory

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文