Background info:
I’m using Microsoft Visual C# 2010 for this project. I want to use a class, System.IO.DirectoryInfo, to get a directory listing. However, the implementation of GetDirectories() doesn’t work for me, since upon throwing an UnauthorizedAccessException exception, the function fails.
I would like to create a DLL that defines a derived class having the same functionality of the DirectoryInfo class, but overrides GetDirectories() so I can have the functionality I need.
The problem:
I must be doing something wrong when trying to call the base constructor. I get the error “‘object’ does not contain a constructor that takes 1 arguments”.
using System;
using System.IO;
namespace CompanyName.System.IO
{
public class FlexibleDirectoryInfo : DirectoryInfo
{
public FlexibleDirectoryInfo(string path) : base(path) {}
[...]
DirectoryInfo does not have a default constructor, and instead has a single constructor taking a string parameter, just like I’m trying to do. However, I’m not sure if it’s resolving the base constructor properly?
I have a feeling this is a simple fix. Please just help point out what I’m overlooking. 🙂
Thanks!
DirectoryInfois a sealed class. So you cannot derive from it.From MSDN:
However, you create a class that inherits FileSystemInfo (superclass for
DirectoryInfo). You’ll have to create most of the implementation, but it’s the only way.