< Summary

Information
Class: Elsa.Alterations.Core.Serialization.AlterationSerializationOptionConfigurator
Assembly: Elsa.Alterations.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Alterations.Core/Serialization/AlterationSerializationOptionConfigurator.cs
Line coverage
60%
Covered lines: 14
Uncovered lines: 9
Coverable lines: 23
Total lines: 43
Line coverage: 60.8%
Branch coverage
16%
Covered branches: 1
Total branches: 6
Branch coverage: 16.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetModifiers()100%11100%

File(s)

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

#LineLine coverage
 1using System.Text.Json.Serialization;
 2using System.Text.Json.Serialization.Metadata;
 3using Elsa.Alterations.Core.Contracts;
 4using Elsa.Alterations.Core.Options;
 5using Elsa.Workflows;
 6using JetBrains.Annotations;
 7using Microsoft.Extensions.Options;
 8
 9namespace Elsa.Alterations.Core.Serialization;
 10
 11/// <summary>
 12/// Add additional <see cref="JsonConverter"/> objects.
 13/// </summary>
 14[UsedImplicitly]
 115public class AlterationSerializationOptionConfigurator(IOptions<AlterationOptions> options) : SerializationOptionsConfig
 16{
 17    /// <inheritdoc />
 18    public override IEnumerable<Action<JsonTypeInfo>> GetModifiers()
 19    {
 58820        var alterationTypes = options.Value.AlterationTypes;
 21
 58822        yield return typeInfo =>
 58823        {
 14333224            if (typeInfo.Type != typeof(IAlteration))
 14333225                return;
 58826
 027            if (typeInfo.Kind != JsonTypeInfoKind.Object)
 028                return;
 58829
 030            var polymorphismOptions = new JsonPolymorphismOptions
 031            {
 032                TypeDiscriminatorPropertyName = "type"
 033            };
 58834
 035            foreach (var alterationType in alterationTypes.ToList())
 58836            {
 037                polymorphismOptions.DerivedTypes.Add(new(alterationType, alterationType.Name));
 58838            }
 58839
 040            typeInfo.PolymorphismOptions = polymorphismOptions;
 58841        };
 58842    }
 43}