using System;
using System.Text;
namespace SabreTools.Wrappers
{
///
/// Generic wrapper around printing methods
///
public static class Printer
{
///
/// Print the item information from a wrapper to console as
/// pretty-printed text
///
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());
}
///
/// Export the item information as a StringBuilder
///
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
///
/// Export the item information as JSON
///
public static string ExportJSON(this IWrapper wrapper)
{
// Ignore unprintable types
if (wrapper is not IPrintable printable)
return string.Empty;
return printable.ExportJSON();
}
#endif
}
}