| | | 1 | | using Elsa.Expressions.Helpers; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Expressions.Models; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// A base class for types that represent a reference to a block of memory. |
| | | 7 | | /// </summary> |
| | | 8 | | public class MemoryBlockReference |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Initializes a new instance of the <see cref="MemoryBlockReference"/> class. |
| | | 12 | | /// </summary> |
| | 4099 | 13 | | public MemoryBlockReference() |
| | | 14 | | { |
| | 4099 | 15 | | } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Initializes a new instance of the <see cref="MemoryBlockReference"/> class. |
| | | 19 | | /// </summary> |
| | 6558 | 20 | | public MemoryBlockReference(string id) => Id = id; |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// The ID of the memory block. |
| | | 24 | | /// </summary> |
| | 37478 | 25 | | public string Id { get; set; } = null!; |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Declares the memory block. |
| | | 29 | | /// </summary> |
| | 1566 | 30 | | public virtual MemoryBlock Declare() => new(); |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Returns true if the memory block is defined in the specified memory register. |
| | | 34 | | /// </summary> |
| | 0 | 35 | | public bool IsDefined(MemoryRegister register) => register.HasBlock(Id); |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Returns the value of the memory block. |
| | | 39 | | /// </summary> |
| | 106 | 40 | | public object? Get(MemoryRegister memoryRegister) => GetBlock(memoryRegister).Value; |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Returns the value of the memory block. |
| | | 44 | | /// </summary> |
| | 0 | 45 | | public T? Get<T>(MemoryRegister memoryRegister) => Get(memoryRegister).ConvertTo<T>(); |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Returns the value of the memory block. |
| | | 49 | | /// </summary> |
| | 26 | 50 | | public object? Get(ExpressionExecutionContext context) => context.Get(this); |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Returns the value of the memory block. |
| | | 54 | | /// </summary> |
| | 0 | 55 | | public T? Get<T>(ExpressionExecutionContext context) => Get(context).ConvertTo<T>(); |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Returns the value of the memory block. |
| | | 59 | | /// </summary> |
| | 2 | 60 | | 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 | | { |
| | 15 | 67 | | var block = GetBlock(memoryRegister); |
| | 15 | 68 | | block.Value = value; |
| | 15 | 69 | | configure?.Invoke(block); |
| | 15 | 70 | | } |
| | | 71 | | |
| | | 72 | | /// <summary> |
| | | 73 | | /// Sets the value of the memory block. |
| | | 74 | | /// </summary> |
| | 230 | 75 | | 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> |
| | 165 | 80 | | 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> |
| | | 87 | | public class MemoryBlockReference<T> : MemoryBlockReference |
| | | 88 | | { |
| | | 89 | | } |