< Summary

Information
Class: Elsa.Workflows.Serialization.Converters.PolymorphicObjectConverterFactory
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Serialization/Converters/PolymorphicObjectConverterFactory.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 56
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor()100%11100%
CanConvert(...)100%1212100%
CreateConverter(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Serialization/Converters/PolymorphicObjectConverterFactory.cs

#LineLine coverage
 1using System.Dynamic;
 2using System.Text.Json;
 3using System.Text.Json.Serialization;
 4using Elsa.Expressions.Contracts;
 5using Elsa.Expressions.Services;
 6
 7namespace Elsa.Workflows.Serialization.Converters;
 8
 9/// <summary>
 10/// A JSON converter factory that creates <see cref="PolymorphicObjectConverter"/> instances.
 11/// </summary>
 12public class PolymorphicObjectConverterFactory : JsonConverterFactory
 13{
 14    private readonly IWellKnownTypeRegistry _wellKnownTypeRegistry;
 15
 16    /// <summary>
 17    /// A JSON converter factory that creates <see cref="PolymorphicObjectConverter"/> instances.
 18    /// </summary>
 1674219    public PolymorphicObjectConverterFactory(IWellKnownTypeRegistry wellKnownTypeRegistry)
 20    {
 1674221        _wellKnownTypeRegistry = wellKnownTypeRegistry;
 1674222    }
 23
 24    /// <summary>
 25    /// Default constructor for use with attributes.
 26    /// </summary>
 402227    public PolymorphicObjectConverterFactory()
 28    {
 402229        _wellKnownTypeRegistry = WellKnownTypeRegistry.CreateDefault();
 402230    }
 31
 32    /// <inheritdoc />
 33    public override bool CanConvert(Type typeToConvert)
 34    {
 7532835        if (typeToConvert.IsClass
 7532836               && typeToConvert == typeof(object)
 7532837               || typeToConvert == typeof(ExpandoObject)
 7532838               || typeToConvert == typeof(Dictionary<string, object>))
 1450639            return true;
 40
 6082241        if (typeToConvert.IsInterface
 6082242               && typeToConvert == typeof(IDictionary<string, object>))
 837343            return true;
 44
 5244945        return false;
 46    }
 47
 48    /// <inheritdoc />
 49    public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
 50    {
 3893351        if (typeof(IDictionary<string, object>).IsAssignableFrom(typeToConvert))
 1479852            return new PolymorphicDictionaryConverter(options, _wellKnownTypeRegistry);
 53
 2413554        return new PolymorphicObjectConverter();
 55    }
 56}