mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-05 22:01:33 +00:00
Printer was really redundant
This commit is contained in:
@@ -179,12 +179,20 @@ namespace InfoPrint.Features
|
||||
return;
|
||||
}
|
||||
|
||||
// If the wrapper is not printable
|
||||
if (wrapper is not IPrintable printable)
|
||||
{
|
||||
Console.WriteLine($"{ft} is not supported for printing!");
|
||||
Console.WriteLine();
|
||||
return;
|
||||
}
|
||||
|
||||
#if NETCOREAPP
|
||||
// If we have the JSON flag
|
||||
if (Json)
|
||||
{
|
||||
// Create the output data
|
||||
string serializedData = wrapper.ExportJSON();
|
||||
string serializedData = printable.ExportJSON();
|
||||
|
||||
// Write the output data
|
||||
using var jsw = new StreamWriter(File.OpenWrite($"{filenameBase}.json"));
|
||||
@@ -194,12 +202,8 @@ namespace InfoPrint.Features
|
||||
#endif
|
||||
|
||||
// Create the output data
|
||||
var builder = wrapper.ExportStringBuilder();
|
||||
if (builder is null)
|
||||
{
|
||||
Console.WriteLine("No item information could be generated");
|
||||
return;
|
||||
}
|
||||
var builder = new StringBuilder();
|
||||
printable.PrintInformation(builder);
|
||||
|
||||
// Only print to console if enabled
|
||||
if (!FileOnly)
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user