summary refs log tree commit diff
path: root/LibGit/Extensions/ObjectExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LibGit/Extensions/ObjectExtensions.cs')
-rw-r--r--LibGit/Extensions/ObjectExtensions.cs15
1 files changed, 15 insertions, 0 deletions
diff --git a/LibGit/Extensions/ObjectExtensions.cs b/LibGit/Extensions/ObjectExtensions.cs
new file mode 100644
index 0000000..2cdeccd
--- /dev/null
+++ b/LibGit/Extensions/ObjectExtensions.cs
@@ -0,0 +1,15 @@
+using System.Text.Json;
+
+namespace LibGit.Extensions;
+
+public static class ObjectExtensions
+{
+    public static string ToJson(this object obj, bool indent = true, bool ignoreNull = false, bool unsafeContent = false)
+    {
+        var jso = new JsonSerializerOptions();
+        if(indent) jso.WriteIndented = true;
+        if(ignoreNull) jso.IgnoreNullValues = true;
+        if(unsafeContent) jso.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
+        return JsonSerializer.Serialize(obj, jso);
+    }
+}
\ No newline at end of file