| | | 1 | | using System.Text.Json; |
| | | 2 | | |
| | | 3 | | // ReSharper disable once CheckNamespace |
| | | 4 | | namespace Elsa.Extensions; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Parses a <see cref="JsonElement"/> into a .NET object. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class JsonElementExtensions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Parses a <see cref="JsonElement"/> into a .NET object. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="jsonElement">The JSON element to parse.</param> |
| | | 15 | | /// <returns>The parsed object.</returns> |
| | | 16 | | public static object? GetValue(this JsonElement jsonElement) |
| | | 17 | | { |
| | 6963 | 18 | | return jsonElement.ValueKind switch |
| | 6963 | 19 | | { |
| | 1427 | 20 | | JsonValueKind.String => jsonElement.GetString(), |
| | 0 | 21 | | JsonValueKind.Number => jsonElement.GetDecimal(), |
| | 282 | 22 | | JsonValueKind.True => true, |
| | 4972 | 23 | | JsonValueKind.False => false, |
| | 282 | 24 | | JsonValueKind.Undefined => null, |
| | 0 | 25 | | JsonValueKind.Null => null, |
| | 0 | 26 | | JsonValueKind.Object => jsonElement.GetRawText(), |
| | 0 | 27 | | JsonValueKind.Array => jsonElement.GetRawText(), |
| | 0 | 28 | | _ => jsonElement.GetRawText() |
| | 6963 | 29 | | }; |
| | | 30 | | } |
| | | 31 | | } |