如果有这样的方法,我想知道如何在System.IO.File中使用c#进行扩展。
我想做一个如下的方法。
// 'CreateDirectoryAndFile is the method I made
System.IO.File.CreateDirectoryAndFile("path"); 但我已经在谷歌上搜索过了,我找不到路。
所以,我被迫像下面这样做。
// I made a FileHelper class for this method.
FileHelper.CreateDirectoryAndFile("path");难道没有办法这样做吗?
发布于 2019-04-24 08:58:05
不能为静态类创建扩展方法。
但是,如果需要“扩展”大量功能,可以为System.IO.File创建包装器。比如:
public class FileWrapper
{
public File CreteFile(string path)
{
}
public File CreateDirectoryAndFile(string path)
{
}
// etc
}https://stackoverflow.com/questions/55826002
复制相似问题