到目前爲止,我創建了以下接口:如何模擬DirectoryInfo類?
public interface IDirectoryInfoWrapper
{
public IFileInfoWrapper[] GetFiles(string searchPattern, SearchOption searchType);
public IDirectoryInfoWrapper[] GetDirectories();
}
我已經經歷的代碼IDirectoryInfoWrapper
更換的DirectoryInfo。一切都順利,直到我發現這一點:
// Check that the directory is valid
DirectoryInfo directoryInfo = new DirectoryInfo(argPath);
if (directoryInfo.Exists == false)
{
throw new ArgumentException
("Invalid IFileFinder.FindFiles Directory Path: " + argPath);
}
這是沒有意義的把構造函數的接口,所以我應該怎麼做這行代碼:
DirectoryInfo directoryInfo = new DirectoryInfo(argPath);
界面做類似的,當然,去wihtout構造,但其與構造函數實現。 –