mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-21 10:49:25 +01:00
Extension method from SDG for testing
This commit is contained in:
@@ -11,6 +11,8 @@ using Flowframes.Data;
|
||||
using System.Management.Automation;
|
||||
using System.Drawing;
|
||||
using Flowframes.MiscUtils;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Flowframes
|
||||
{
|
||||
@@ -396,5 +398,18 @@ namespace Flowframes
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(s);
|
||||
}
|
||||
|
||||
public static string ToJson(this object o, bool indent = false, bool ignoreErrors = true)
|
||||
{
|
||||
var settings = new JsonSerializerSettings();
|
||||
|
||||
if (ignoreErrors)
|
||||
settings.Error = (s, e) => { e.ErrorContext.Handled = true; };
|
||||
|
||||
// Serialize enums as strings.
|
||||
settings.Converters.Add(new StringEnumConverter());
|
||||
|
||||
return JsonConvert.SerializeObject(o, indent ? Formatting.Indented : Formatting.None, settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user