Skip to content

Commit

Permalink
feat: add read/write extensions to IFileInfo (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasyTeddy authored Mar 8, 2024
1 parent 55aaeeb commit 355cef3
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/System.IO.Abstractions.Extensions/IFileInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,54 @@ public static void AppendLines(this IFileInfo file, IEnumerable<string> lines)
}
}

/// <inheritdoc cref="IFile.AppendAllLines(string, IEnumerable{string})"/>
public static void AppendAllLines(this IFileInfo file, IEnumerable<string> contents)
{
file.FileSystem.File.AppendAllLines(file.FullName, contents);
}

/// <inheritdoc cref="IFile.AppendAllText(string, string)"/>
public static void AppendAllText(this IFileInfo file, string contents)
{
file.FileSystem.File.AppendAllText(file.FullName, contents);
}

/// <inheritdoc cref="IFile.ReadAllBytes(string)"/>
public static byte[] ReadAllBytes(this IFileInfo file)
{
return file.FileSystem.File.ReadAllBytes(file.FullName);
}

/// <inheritdoc cref="IFile.ReadAllLines(string)"/>
public static string[] ReadAllLines(this IFileInfo file)
{
return file.FileSystem.File.ReadAllLines(file.FullName);
}

/// <inheritdoc cref="IFile.ReadAllText(string)"/>
public static string ReadAllText(this IFileInfo file)
{
return file.FileSystem.File.ReadAllText(file.FullName);
}

/// <inheritdoc cref="IFile.WriteAllBytes(string, byte[])"/>
public static void WriteAllBytes(this IFileInfo file, byte[] bytes)
{
file.FileSystem.File.WriteAllBytes(file.FullName, bytes);
}

/// <inheritdoc cref="IFile.WriteAllLines(string, IEnumerable{string})"/>
public static void WriteAllLines(this IFileInfo file, IEnumerable<string> contents)
{
file.FileSystem.File.WriteAllLines(file.FullName, contents);
}

/// <inheritdoc cref="IFile.WriteAllText(string, string)"/>
public static void WriteAllText(this IFileInfo file, string contents)
{
file.FileSystem.File.WriteAllText(file.FullName, contents);
}

private static FileMode GetWriteFileMode(IFileInfo info, bool overwrite)
{
if (!overwrite && info.Exists)
Expand Down

0 comments on commit 355cef3

Please sign in to comment.