< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Read(...)0%620%
Write(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Serialization;
 3using Elsa.Expressions.Models;
 4
 5namespace Elsa.Workflows.Serialization.Converters;
 6
 7/// <summary>
 8/// Prevents System.Text.Json from trying to serialize the compiled delegate.
 9/// Always emits null and cannot rehydrate a Func.
 10/// </summary>
 11public class FuncExpressionValueConverter : JsonConverter<Func<ExpressionExecutionContext, ValueTask<object>>>
 12{
 13    public override Func<ExpressionExecutionContext, ValueTask<object>> Read(ref Utf8JsonReader reader, Type typeToConve
 14    {
 15        // Skip whatever value is in the JSON (probably null).
 016        if (reader.TokenType != JsonTokenType.Null)
 017            reader.Skip();
 18
 19        // We can't deserialize a delegate, so return null.
 020        return null!;
 21    }
 22
 23    public override void Write(Utf8JsonWriter writer, Func<ExpressionExecutionContext, ValueTask<object>> value, JsonSer
 24    {
 25        // Emit a JSON null instead of trying to serialize the delegate
 026        writer.WriteNullValue();
 027    }
 28}