mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-05 22:01:33 +00:00
This change looks dramatic, but it's just separating out the already-split namespaces into separate top-level folders. In theory, every single one could be built into their own Nuget package. `SabreTools.Serialization` still builds the normal Nuget package that is used by all other projects and includes all namespaces.
56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using System;
|
|
using System.Text;
|
|
|
|
namespace SabreTools.Wrappers
|
|
{
|
|
/// <summary>
|
|
/// Generic wrapper around printing methods
|
|
/// </summary>
|
|
public static class Printer
|
|
{
|
|
/// <summary>
|
|
/// Print the item information from a wrapper to console as
|
|
/// pretty-printed text
|
|
/// </summary>
|
|
public static void PrintToConsole(this IWrapper wrapper)
|
|
{
|
|
var sb = wrapper.ExportStringBuilder();
|
|
if (sb is null)
|
|
{
|
|
Console.WriteLine("No item information could be generated");
|
|
return;
|
|
}
|
|
|
|
Console.WriteLine(sb.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Export the item information as a StringBuilder
|
|
/// </summary>
|
|
public static StringBuilder? ExportStringBuilder(this IWrapper wrapper)
|
|
{
|
|
// Ignore unprintable types
|
|
if (wrapper is not IPrintable printable)
|
|
return null;
|
|
|
|
var builder = new StringBuilder();
|
|
printable.PrintInformation(builder);
|
|
return builder;
|
|
}
|
|
|
|
#if NETCOREAPP
|
|
/// <summary>
|
|
/// Export the item information as JSON
|
|
/// </summary>
|
|
public static string ExportJSON(this IWrapper wrapper)
|
|
{
|
|
// Ignore unprintable types
|
|
if (wrapper is not IPrintable printable)
|
|
return string.Empty;
|
|
|
|
return printable.ExportJSON();
|
|
}
|
|
#endif
|
|
}
|
|
}
|