Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8154157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:14:51+00:00 2026-06-06T16:14:51+00:00

So far I created the following interface: public interface IDirectoryInfoWrapper { public IFileInfoWrapper[] GetFiles(string

  • 0

So far I created the following interface:

  public interface IDirectoryInfoWrapper
  {
    public IFileInfoWrapper[] GetFiles(string searchPattern, SearchOption searchType);
    public IDirectoryInfoWrapper[] GetDirectories();
  }

I’ve been going through the code replacing DirectoryInfo with IDirectoryInfoWrapper. All was going well until I found this:

  // Check that the directory is valid
  DirectoryInfo directoryInfo = new DirectoryInfo( argPath );
  if ( directoryInfo.Exists == false )
  {
    throw new ArgumentException
        ("Invalid IFileFinder.FindFiles Directory Path: " + argPath);
  }

It makes no sense to put the constructor in the interface, so what should I do with this line of code:

DirectoryInfo directoryInfo = new DirectoryInfo( argPath );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:14:53+00:00Added an answer on June 6, 2026 at 4:14 pm

    I see two obvious choices:

    1. Replace DirectoryInfo with your own wrapper implementation there (not ideal)
    2. Create a factory that can make IDirectoryInfoWrapper instances. You could make a Create function with overloads for each constructor you wanted to use.

    I’m assuming you are doing this with dependency-injection, which would mean now you just inject that factory into any class needing to create new directory info objects.

    Also, you would want to modify the wrapper interface to expose that Exists property

    Edit: if you’re doing this to try to unit-test something (which seems likely) then you might try reading Misko Hevery. Every time you use the new operator in C#, you have a point where you cannot inject something at runtime. This makes it very difficult to test anything using new in any but the most trivial of cases. For anything that isn’t a simple data object, I pretty much always use a factory.

    Edit II:

    You’re delegating the construction to the factory, so that’s where you use the DirectoryInfo real constructor:

    class Factory : IFactory 
    {
      IDirectoryInfoWrapper Create(string arg)
      {
        var dirInfo = new DirectoryInfo(arg);
        var wrapper = new DirectoryInfoWrapper(dirInfo);
        return wrapper;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following interface in my project. public interface Setting<T> { T Value
The following code does not always create the file. As far as I noticed,
All my apps that i've created so far do this. It does nothing to
I created an application in MonoDevelop, the application runs correctly (as far as I
I have created VIEWS and PartialVIEWS, but so far, i have seen that VIEWS,
I've created an open graph action, and so far I can only seem to
As far as I know, only the convenience methods return created objects with an
I'm working on creating a 3D landscape. So far I've got a mesh created
I am developing a live update for my application. So far, I have created
I have created an interface that my DbContext class implements, this enables me to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.