Why Can't I Inherit IO.Directory?
Asked Answered
L

4

2

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.

Loop answered 25/9, 2008 at 20:17 Comment(2)
Thank you Jeff Atwood for editing my post and adding VB.NET tag. No wonder you can't blog anymore!Loop
Lol, he changed content. I added the tag :)Burchette
E
11

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.

Electromotive answered 25/9, 2008 at 20:19 Comment(0)
I
5

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

Immethodical answered 25/9, 2008 at 20:18 Comment(1)
I know, but what kind of programmer doesn't argue semantics? ;)Khartoum
S
1

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.

Studio answered 25/9, 2008 at 20:19 Comment(2)
I don't care. I am trying to rename a directory, not move it.Loop
Won't moving the directory to the new name effectively rename it?Mcgary
M
0

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

Mycorrhiza answered 25/9, 2008 at 22:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.