.netextensibility

How can I inform the implementor of my Interface that the "path" parameter represents a folder?


I am about to define an interface in my application that plug-in writers can implement to provide user-defined "export" capabilities. It'll look something like this:

public interface IFooExporter
{
    void ExportFoo(Foo foo, string path);
}

However, I need to let the plug-in writers know (explicitly, not just in documentation) that "path" represents a folder, not a filename. It's their responsibility to create the files as part of the export process.

What's the best way to enforce that a path is a folder and not a filename? My best guess right now is to use DirectoryInfo instead of string:

public interface IFooExporter
{
    void ExportFoo(Foo foo, DirectoryInfo folder);
}

Is that a good solution, or are there pitfalls I'm not aware of with passing DirectoryInfo instances around?


Solution

  • Because you are not implementing the solution, then I agree with you solution of using the DirectoryInfo as a parameter. If you specify a string then there is no way to stop any string being passed.