< Summary

Information
Class: Elsa.Alterations.Core.Serialization.AlterationSerializer
Assembly: Elsa.Alterations.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations.Core/Serialization/AlterationSerializer.cs
Line coverage
20%
Covered lines: 2
Uncovered lines: 8
Coverable lines: 10
Total lines: 49
Line coverage: 20%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Serialize(...)100%210%
SerializeMany(...)100%210%
Deserialize(...)100%210%
DeserializeMany(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations.Core/Serialization/AlterationSerializer.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Text.Json;
 3using Elsa.Alterations.Core.Contracts;
 4using Elsa.Common.Serialization;
 5
 6namespace Elsa.Alterations.Core.Serialization;
 7
 8/// <summary>
 9/// A serializer for <see cref="IAlteration"/> objects.
 10/// </summary>
 11public class AlterationSerializer : ConfigurableSerializer, IAlterationSerializer
 12{
 13    /// <inheritdoc />
 114    public AlterationSerializer(IServiceProvider serviceProvider) : base(serviceProvider)
 15    {
 116    }
 17
 18    /// <inheritdoc />
 19    [RequiresUnreferencedCode("The type of the alteration must be known at compile time.")]
 20    public string Serialize(IAlteration alteration)
 21    {
 022        var options = GetOptions();
 023        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    {
 030        var options = GetOptions();
 031        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    {
 038        var options = GetOptions();
 039        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    {
 046        var options = GetOptions();
 047        return JsonSerializer.Deserialize<IAlteration[]>(json, options)!;
 48    }
 49}