< Summary

Information
Class: Chronicler.RecordLinks
Assembly: Chronicler
File(s): /home/runner/work/Chronicler/Chronicler/src/Chronicler/Recording/Links/RecordLinks.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 71
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Look(...)100%11100%
LookDeferred(...)100%22100%

File(s)

/home/runner/work/Chronicler/Chronicler/src/Chronicler/Recording/Links/RecordLinks.cs

#LineLine coverage
 1//=======================================================================
 2// RecordLinks.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System;
 9
 10namespace Chronicler;
 11
 12/// <summary>
 13/// Records stable IDs for links to host-owned values.
 14/// </summary>
 15public static class RecordLinks
 16{
 17    /// <summary>
 18    /// Records a link that must resolve as soon as it is read.
 19    /// </summary>
 20    /// <typeparam name="T">The declared type used for registry lookup.</typeparam>
 21    /// <param name="chronicler">The active pass supplied to <see cref="IRecordable.RecordData"/>.</param>
 22    /// <param name="value">
 23    /// The value to identify on save. On load, receives the resolved value or the default for a missing or null entry.
 24    /// An unresolved ID leaves this value unchanged.
 25    /// </param>
 26    /// <param name="name">The stable field name to use on both save and load.</param>
 27    /// <param name="slot">An optional identity domain. Null or empty selects the default slot.</param>
 28    /// <exception cref="InvalidOperationException">
 29    /// A non-null value has no stable ID on save, or a present link ID cannot resolve on load.
 30    /// </exception>
 31    public static void Look<T>(IChronicler chronicler, ref T value, string name, string? slot = null)
 32    {
 3433        chronicler.LookLink(ref value, name, slot);
 2834    }
 35
 36    /// <summary>
 37    /// Records a link whose assignment may wait until the graph has loaded.
 38    /// </summary>
 39    /// <typeparam name="T">The declared type used for registry lookup.</typeparam>
 40    /// <param name="chronicler">The active pass supplied to <see cref="IRecordable.RecordData"/>.</param>
 41    /// <param name="value">The value to identify on save. The callback applies any loaded value.</param>
 42    /// <param name="name">The stable field name to use on both save and load.</param>
 43    /// <param name="assignLoadedValue">
 44    /// Applies the resolved value, or the default of <typeparamref name="T"/> for a missing or null entry.
 45    /// The load context retains this callback while the link is queued.
 46    /// </param>
 47    /// <param name="slot">An optional identity domain. Null or empty selects the default slot.</param>
 48    /// <remarks>
 49    /// On load, the callback runs immediately if the target is available or the entry is missing or null.
 50    /// Otherwise, <see cref="ChronicleContext.ResolveDeferredLinks"/> invokes it when the target resolves.
 51    /// </remarks>
 52    /// <exception cref="ArgumentNullException"><paramref name="assignLoadedValue"/> is null.</exception>
 53    /// <exception cref="InvalidOperationException">A non-null value has no stable ID on save.</exception>
 54    public static void LookDeferred<T>(
 55        IChronicler chronicler,
 56        T value,
 57        string name,
 58        Action<T> assignLoadedValue,
 59        string? slot = null)
 60    {
 2361        if (assignLoadedValue == null)
 162            throw new ArgumentNullException(nameof(assignLoadedValue));
 63
 2264        chronicler.LookLink(
 2265            ref value,
 2266            name,
 2267            slot,
 2268            RecordLinkResolveMode.Deferred,
 2269            assignLoadedValue);
 2270    }
 71}