fix: adding some methods for getting text out of an entity easier
This commit is contained in:
parent
28c4ab850e
commit
42cae6b133
2 changed files with 33 additions and 7 deletions
|
@ -33,13 +33,10 @@ public static class NitrideYamlEntityExtensions
|
|||
this Entity entity,
|
||||
IDeserializer deserializer)
|
||||
{
|
||||
if (!entity.TryGet(out ITextContent content))
|
||||
{
|
||||
return default;
|
||||
}
|
||||
string? text = entity.GetText();
|
||||
|
||||
string text = content.GetText();
|
||||
|
||||
return deserializer.Deserialize<TType>(text);
|
||||
return text != null
|
||||
? deserializer.Deserialize<TType>(text)
|
||||
: default;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using System.IO;
|
||||
|
||||
using Gallium;
|
||||
|
||||
namespace Nitride.Contents;
|
||||
|
||||
public static class TextContentExtensions
|
||||
|
@ -18,4 +20,31 @@ public static class TextContentExtensions
|
|||
|
||||
return writer.ToString();
|
||||
}
|
||||
|
||||
public static string? GetText(this IBinaryContent content)
|
||||
{
|
||||
if (content is ITextContentConvertable convertableContent)
|
||||
{
|
||||
return convertableContent
|
||||
.ToTextContent()
|
||||
.GetText();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string? GetText(this Entity entity)
|
||||
{
|
||||
if (entity.TryGet(out ITextContent textContent))
|
||||
{
|
||||
return textContent.GetText();
|
||||
}
|
||||
|
||||
if (entity.TryGet(out IBinaryContent binaryContent))
|
||||
{
|
||||
return binaryContent.GetText();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue