| | | 1 | | using System.Diagnostics.CodeAnalysis; |
| | | 2 | | using System.Text.Json; |
| | | 3 | | using Elsa.Alterations.Core.Contracts; |
| | | 4 | | using Elsa.Common.Serialization; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Alterations.Core.Serialization; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// A serializer for <see cref="IAlteration"/> objects. |
| | | 10 | | /// </summary> |
| | | 11 | | public class AlterationSerializer : ConfigurableSerializer, IAlterationSerializer |
| | | 12 | | { |
| | | 13 | | /// <inheritdoc /> |
| | 1 | 14 | | public AlterationSerializer(IServiceProvider serviceProvider) : base(serviceProvider) |
| | | 15 | | { |
| | 1 | 16 | | } |
| | | 17 | | |
| | | 18 | | /// <inheritdoc /> |
| | | 19 | | [RequiresUnreferencedCode("The type of the alteration must be known at compile time.")] |
| | | 20 | | public string Serialize(IAlteration alteration) |
| | | 21 | | { |
| | 0 | 22 | | var options = GetOptions(); |
| | 0 | 23 | | return JsonSerializer.Serialize(alteration, options); |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | [RequiresUnreferencedCode("The type of the alteration must be known at compile time.")] |
| | | 28 | | public string SerializeMany(IEnumerable<IAlteration> alterations) |
| | | 29 | | { |
| | 0 | 30 | | var options = GetOptions(); |
| | 0 | 31 | | return JsonSerializer.Serialize(alterations.ToArray(), options); |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <inheritdoc /> |
| | | 35 | | [RequiresUnreferencedCode("The type of the alteration must be known at compile time.")] |
| | | 36 | | public IAlteration Deserialize(string json) |
| | | 37 | | { |
| | 0 | 38 | | var options = GetOptions(); |
| | 0 | 39 | | return JsonSerializer.Deserialize<IAlteration>(json, options)!; |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | | 43 | | [RequiresUnreferencedCode("The type of the alteration must be known at compile time.")] |
| | | 44 | | public IEnumerable<IAlteration> DeserializeMany(string json) |
| | | 45 | | { |
| | 0 | 46 | | var options = GetOptions(); |
| | 0 | 47 | | return JsonSerializer.Deserialize<IAlteration[]>(json, options)!; |
| | | 48 | | } |
| | | 49 | | } |