0

If there is a way, I want to know that the way to make extension method to System.IO.File in c#.

I want to make a method like below.

// 'CreateDirectoryAndFile is the method I made
System.IO.File.CreateDirectoryAndFile("path"); 

but I've searched it on google, I can't find the way.

So, I was forced to try to do like below.

// I made a FileHelper class for this method.
FileHelper.CreateDirectoryAndFile("path");

Isn't there a way to do like this?

canton7
  • 37,633
  • 3
  • 64
  • 77
Masuri
  • 894
  • 2
  • 9
  • 19

1 Answers1

0

You can't create extension method for static class.

But, you can create wrapper for System.IO.File if you need to 'extend' lot of functionality. Like:

public class FileWrapper 
{
   public File CreteFile(string path)
   {
   }

   public File CreateDirectoryAndFile(string path)
   {
   }

   // etc
}