mirror of https://github.com/n00mkrad/flowframes
Extension method from SDG for testing
This commit is contained in:
parent
355d44a5b3
commit
f4bf63b5a7
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue