diff options
Diffstat (limited to 'MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs')
-rw-r--r-- | MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs b/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs new file mode 100644 index 0000000..cf798ce --- /dev/null +++ b/MatrixRoomUtils.Core/Extensions/ObjectExtensions.cs @@ -0,0 +1,14 @@ +using System.Text.Json; + +namespace MatrixRoomUtils.Extensions; + +public static class ObjectExtensions +{ + public static string ToJson(this object obj, bool indent = true, bool ignoreNull = false) + { + var jso = new JsonSerializerOptions(); + if(indent) jso.WriteIndented = true; + if(ignoreNull) jso.IgnoreNullValues = true; + return JsonSerializer.Serialize(obj, jso); + } +} \ No newline at end of file |