Skip to content

Commit 355cef3

Browse files
authored
feat: add read/write extensions to IFileInfo (#67)
1 parent 55aaeeb commit 355cef3

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/System.IO.Abstractions.Extensions/IFileInfoExtensions.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,54 @@ public static void AppendLines(this IFileInfo file, IEnumerable<string> lines)
117117
}
118118
}
119119

120+
/// <inheritdoc cref="IFile.AppendAllLines(string, IEnumerable{string})"/>
121+
public static void AppendAllLines(this IFileInfo file, IEnumerable<string> contents)
122+
{
123+
file.FileSystem.File.AppendAllLines(file.FullName, contents);
124+
}
125+
126+
/// <inheritdoc cref="IFile.AppendAllText(string, string)"/>
127+
public static void AppendAllText(this IFileInfo file, string contents)
128+
{
129+
file.FileSystem.File.AppendAllText(file.FullName, contents);
130+
}
131+
132+
/// <inheritdoc cref="IFile.ReadAllBytes(string)"/>
133+
public static byte[] ReadAllBytes(this IFileInfo file)
134+
{
135+
return file.FileSystem.File.ReadAllBytes(file.FullName);
136+
}
137+
138+
/// <inheritdoc cref="IFile.ReadAllLines(string)"/>
139+
public static string[] ReadAllLines(this IFileInfo file)
140+
{
141+
return file.FileSystem.File.ReadAllLines(file.FullName);
142+
}
143+
144+
/// <inheritdoc cref="IFile.ReadAllText(string)"/>
145+
public static string ReadAllText(this IFileInfo file)
146+
{
147+
return file.FileSystem.File.ReadAllText(file.FullName);
148+
}
149+
150+
/// <inheritdoc cref="IFile.WriteAllBytes(string, byte[])"/>
151+
public static void WriteAllBytes(this IFileInfo file, byte[] bytes)
152+
{
153+
file.FileSystem.File.WriteAllBytes(file.FullName, bytes);
154+
}
155+
156+
/// <inheritdoc cref="IFile.WriteAllLines(string, IEnumerable{string})"/>
157+
public static void WriteAllLines(this IFileInfo file, IEnumerable<string> contents)
158+
{
159+
file.FileSystem.File.WriteAllLines(file.FullName, contents);
160+
}
161+
162+
/// <inheritdoc cref="IFile.WriteAllText(string, string)"/>
163+
public static void WriteAllText(this IFileInfo file, string contents)
164+
{
165+
file.FileSystem.File.WriteAllText(file.FullName, contents);
166+
}
167+
120168
private static FileMode GetWriteFileMode(IFileInfo info, bool overwrite)
121169
{
122170
if (!overwrite && info.Exists)

0 commit comments

Comments
 (0)