< Summary

Information
Class: Elsa.Extensions.OutputExtensions
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/OutputExtensions.cs
Line coverage
50%
Covered lines: 8
Uncovered lines: 8
Coverable lines: 16
Total lines: 78
Line coverage: 50%
Branch coverage
28%
Covered branches: 4
Total branches: 14
Branch coverage: 28.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CreateInput(...)100%210%
Set(...)100%11100%
Set(...)100%210%
Set(...)100%210%
Set(...)100%210%
GetTargetType(...)20%291042.85%
HasTarget(...)50%44100%
ParseValue(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/OutputExtensions.cs

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2using Elsa.Expressions.Helpers;
 3using Elsa.Expressions.Models;
 4using Elsa.Workflows;
 5using Elsa.Workflows.Memory;
 6using Elsa.Workflows.Models;
 7
 8// ReSharper disable once CheckNamespace
 9namespace Elsa.Extensions;
 10
 11/// <summary>
 12/// Provides a set of helper extensions to <see cref="Output{T}"/>.
 13/// </summary>
 14public static class OutputExtensions
 15{
 16    /// <summary>
 17    /// Creates an input that references the specified output's value.
 18    /// </summary>
 019    public static Input<T> CreateInput<T>(this Output output) => new(output);
 20
 21    extension<T>(Output<T>? output)
 22    {
 23        /// <summary>
 24        /// Sets the output to the specified value.
 25        /// </summary>
 21626        public void Set(ActivityExecutionContext context, T? value, [CallerArgumentExpression("output")] string? outputN
 27
 28        /// <summary>
 29        /// Sets the output to the specified value.
 30        /// </summary>
 031        public void Set(ExpressionExecutionContext context, T? value) => context.Set(output, value);
 32
 33        /// <summary>
 34        /// Sets the output to the specified value.
 35        /// </summary>
 036        public void Set(ActivityExecutionContext context, Variable<T> value) => context.Set(output, value.Get(context));
 37
 38        /// <summary>
 39        /// Sets the output to the specified value.
 40        /// </summary>
 041        public void Set(ExpressionExecutionContext context, Variable<T> value) => context.Set(output, value.Get(context)
 42    }
 43
 44    extension(Output? output)
 45    {
 46        /// <summary>
 47        /// Gets the target type of the specified variable type, if any, linked to the output.
 48        /// </summary>
 49        public Type? GetTargetType(ActivityExecutionContext context)
 50        {
 20651            var memoryBlockReference = output?.MemoryBlockReference();
 52
 20653            if (memoryBlockReference is null)
 20654                return null;
 55
 056            if(!context.ExpressionExecutionContext.TryGetBlock(memoryBlockReference, out var memoryBlock))
 057                return null;
 58
 059            var parsedContentVariableType = (memoryBlock.Metadata as VariableBlockMetadata)?.Variable.GetType();
 060            return parsedContentVariableType?.GenericTypeArguments.FirstOrDefault();
 61        }
 62
 63        /// <summary>
 64        /// Returns a value indicating whether the output has a target.
 65        /// </summary>
 66        public bool HasTarget(ActivityExecutionContext context)
 67        {
 2868            var memoryBlockReference = output?.MemoryBlockReference();
 2869            return memoryBlockReference is not null && context.ExpressionExecutionContext.TryGetBlock(memoryBlockReferen
 70        }
 71    }
 72
 73    public static object? ParseValue(this Output output, object? value)
 74    {
 3175        var genericType = output.GetType();
 3176        return VariableExtensions.ParseValue(genericType, value);
 77    }
 78}