< Summary

Information
Class: Elsa.Expressions.Models.MemoryBlockReference
Assembly: Elsa.Expressions
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Models/MemoryBlockReference.cs
Line coverage
82%
Covered lines: 14
Uncovered lines: 3
Coverable lines: 17
Total lines: 89
Line coverage: 82.3%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
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%
get_Id()100%11100%
Declare()100%11100%
IsDefined(...)100%210%
Get(...)100%11100%
Get(...)100%210%
Get(...)100%11100%
Get(...)100%210%
TryGet(...)100%11100%
Set(...)50%22100%
Set(...)100%11100%
GetBlock(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Models/MemoryBlockReference.cs

#LineLine coverage
 1using Elsa.Expressions.Helpers;
 2
 3namespace Elsa.Expressions.Models;
 4
 5/// <summary>
 6/// A base class for types that represent a reference to a block of memory.
 7/// </summary>
 8public class MemoryBlockReference
 9{
 10    /// <summary>
 11    /// Initializes a new instance of the <see cref="MemoryBlockReference"/> class.
 12    /// </summary>
 409913    public MemoryBlockReference()
 14    {
 409915    }
 16
 17    /// <summary>
 18    /// Initializes a new instance of the <see cref="MemoryBlockReference"/> class.
 19    /// </summary>
 655820    public MemoryBlockReference(string id) => Id = id;
 21
 22    /// <summary>
 23    /// The ID of the memory block.
 24    /// </summary>
 3747825    public string Id { get; set; } = null!;
 26
 27    /// <summary>
 28    /// Declares the memory block.
 29    /// </summary>
 156630    public virtual MemoryBlock Declare() => new();
 31
 32    /// <summary>
 33    /// Returns true if the memory block is defined in the specified memory register.
 34    /// </summary>
 035    public bool IsDefined(MemoryRegister register) => register.HasBlock(Id);
 36
 37    /// <summary>
 38    /// Returns the value of the memory block.
 39    /// </summary>
 10640    public object? Get(MemoryRegister memoryRegister) => GetBlock(memoryRegister).Value;
 41
 42    /// <summary>
 43    /// Returns the value of the memory block.
 44    /// </summary>
 045    public T? Get<T>(MemoryRegister memoryRegister) => Get(memoryRegister).ConvertTo<T>();
 46
 47    /// <summary>
 48    /// Returns the value of the memory block.
 49    /// </summary>
 2650    public object? Get(ExpressionExecutionContext context) => context.Get(this);
 51
 52    /// <summary>
 53    /// Returns the value of the memory block.
 54    /// </summary>
 055    public T? Get<T>(ExpressionExecutionContext context) => Get(context).ConvertTo<T>();
 56
 57    /// <summary>
 58    /// Returns the value of the memory block.
 59    /// </summary>
 260    public bool TryGet(ExpressionExecutionContext context, out object? value) => context.TryGet(this, out value);
 61
 62    /// <summary>
 63    /// Sets the value of the memory block.
 64    /// </summary>
 65    public void Set(MemoryRegister memoryRegister, object? value, Action<MemoryBlock>? configure = null)
 66    {
 1567        var block = GetBlock(memoryRegister);
 1568        block.Value = value;
 1569        configure?.Invoke(block);
 1570    }
 71
 72    /// <summary>
 73    /// Sets the value of the memory block.
 74    /// </summary>
 23075    public void Set(ExpressionExecutionContext context, object? value, Action<MemoryBlock>? configure = null) => context
 76
 77    /// <summary>
 78    /// Returns the <see cref="MemoryBlock"/> pointed to by the specified memory block reference.
 79    /// </summary>
 16580    public MemoryBlock GetBlock(MemoryRegister memoryRegister) => memoryRegister.TryGetBlock(Id, out var location) ? loc
 81}
 82
 83/// <summary>
 84/// A base class for types that represent a reference to a block of memory.
 85/// </summary>
 86/// <typeparam name="T">The type of the memory block.</typeparam>
 87public class MemoryBlockReference<T> : MemoryBlockReference
 88{
 89}