51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using System.IO;
|
|
|
|
using MfGames.Gallium;
|
|
|
|
namespace MfGames.Nitride.Contents;
|
|
|
|
public static class TextContentExtensions
|
|
{
|
|
public static string GetTextContentString(this ITextContent content)
|
|
{
|
|
var writer = new StringWriter();
|
|
using TextReader reader = content.GetReader();
|
|
string? line = reader.ReadLine();
|
|
|
|
while (line != null)
|
|
{
|
|
writer.WriteLine(line);
|
|
line = reader.ReadLine();
|
|
}
|
|
|
|
return writer.ToString();
|
|
}
|
|
|
|
public static string? GetTextContentString(this IBinaryContent content)
|
|
{
|
|
if (content is ITextContentConvertable convertableContent)
|
|
{
|
|
return convertableContent
|
|
.ToTextContent()
|
|
.GetTextContentString();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static string? GetTextContentString(this Entity entity)
|
|
{
|
|
if (entity.TryGet(out ITextContent textContent))
|
|
{
|
|
return textContent.GetTextContentString();
|
|
}
|
|
|
|
if (entity.TryGet(out IBinaryContent binaryContent))
|
|
{
|
|
return binaryContent.GetTextContentString();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|