This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-io-cil/src/MfGames.IO/Extensions/FileInfoExtensions.cs
Dylan R. E. Moonfire 5adb9ccc52 feat: initial commit
2021-09-11 00:54:27 -05:00

57 lines
1.8 KiB
C#

using System.IO;
using System.Text;
namespace MfGames.IO.Extensions
{
/// <summary>
/// Useful extension methods for FileInfo.
/// </summary>
public static class FileInfoExtensions
{
/// <summary>
/// Reads all the text from a FileInfo object.
/// </summary>
/// <param name="file">The file to read from.</param>
/// <returns>The text contents.</returns>
public static string ReadAllText(this FileInfo file)
{
return File.ReadAllText(file.FullName);
}
/// <summary>
/// Reads all the text from a FileInfo object.
/// </summary>
/// <param name="file">The file to read from.</param>
/// <param name="encoding">The encoding to use.</param>
/// <returns>The text contents.</returns>
public static string ReadAllText(this FileInfo file, Encoding encoding)
{
return File.ReadAllText(file.FullName, encoding);
}
/// <summary>
/// Writes out all the text to the given file.
/// </summary>
/// <param name="file">The file to write to.</param>
/// <param name="text">The text to write out.</param>
public static void WriteAllText(this FileInfo file, string text)
{
File.WriteAllText(file.FullName, text);
}
/// <summary>
/// Writes out all the text to the given file.
/// </summary>
/// <param name="file">The file to write to.</param>
/// <param name="text">The text to write out.</param>
/// <param name="encoding">The encoding to use.</param>
public static void WriteAllText(
this FileInfo file,
string text,
Encoding encoding)
{
File.WriteAllText(file.FullName, text, encoding);
}
}
}