为什么我不能继承IO.Directory?
-
02-07-2019 - |
题
为什么我不能在 VB.NET
中创建 class
inherits
System.IO.Directory
?根据Lutz Roeder的说法,不声明为 NotInheritable
!
我想创建一个实用程序类
,它为 Directory类
添加功能。例如,我想添加 Directory.Move
函数。
请指教,我会寄给你六包。好的,没关系,我不会送你任何东西,但如果你今晚来到酒吧,我会把你挂起,然后在游泳池里打败你。
解决方案
来自.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
您不能从静态类继承。
其他提示
您使用的是
如果您使用DirectoryInfo类,则可以访问MoveTo函数。
编辑:我会纠正自己......静态目录类已经有了一个Move方法。
我猜想Reflector没有正确地为VB拾取密封属性(或者可能只是没有正确显示它)。如果你看看IL,它是密封的:
class public abstract auto ansi 密封 beforefieldinit目录
不隶属于 StackOverflow