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-nitride-cil/src/MfGames.Nitride/Contents/FileTextContent.cs

47 lines
1,021 B
C#
Raw Normal View History

2021-09-07 05:15:45 +00:00
using System;
using System.IO;
using System.Text;
2022-09-06 05:53:22 +00:00
namespace MfGames.Nitride.Contents;
/// <summary>
/// A text content provider based on a file in the file system.
/// </summary>
public class FileTextContent : ITextContent, IBinaryContentConvertable
2021-09-07 05:15:45 +00:00
{
private readonly string path;
public FileTextContent(string path)
2021-09-07 05:15:45 +00:00
{
this.path = path ?? throw new ArgumentNullException(nameof(path));
}
2021-09-07 05:15:45 +00:00
public FileTextContent(FileInfo file)
{
if (file == null)
2021-09-07 05:15:45 +00:00
{
throw new ArgumentNullException(nameof(file));
2021-09-07 05:15:45 +00:00
}
this.path = file.FullName;
}
2021-09-07 05:15:45 +00:00
/// <inheritdoc />
public TextReader GetReader()
{
return new StreamReader(
File.Open(
this.path,
FileMode.Open,
FileAccess.Read,
FileShare.Read),
Encoding.UTF8);
}
2021-09-07 05:15:45 +00:00
/// <inheritdoc />
public IBinaryContent ToBinaryContent()
{
return new FileBinaryContent(this.path);
2021-09-07 05:15:45 +00:00
}
}