-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathDriveInfoFactory.cs
More file actions
54 lines (47 loc) · 1.47 KB
/
DriveInfoFactory.cs
File metadata and controls
54 lines (47 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace System.IO.Abstractions
{
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
internal class DriveInfoFactory : IDriveInfoFactory
{
private readonly IFileSystem fileSystem;
/// <summary>
/// Base factory class for creating a <see cref="IDriveInfo"/>
/// </summary>
public DriveInfoFactory(IFileSystem fileSystem)
{
this.fileSystem = fileSystem;
}
/// <inheritdoc />
public IFileSystem FileSystem
=> fileSystem;
/// <inheritdoc />
public IDriveInfo[] GetDrives()
{
var driveInfos = DriveInfo.GetDrives();
var driveInfoWrappers = new DriveInfoBase[driveInfos.Length];
for (int index = 0; index < driveInfos.Length; index++)
{
var driveInfo = driveInfos[index];
driveInfoWrappers[index] = new DriveInfoWrapper(fileSystem, driveInfo);
}
return driveInfoWrappers;
}
/// <inheritdoc />
public IDriveInfo New(string driveName)
{
var realDriveInfo = new DriveInfo(driveName);
return new DriveInfoWrapper(fileSystem, realDriveInfo);
}
/// <inheritdoc />
public IDriveInfo Wrap(DriveInfo driveInfo)
{
if (driveInfo == null)
{
return null;
}
return new DriveInfoWrapper(fileSystem, driveInfo);
}
}
}