Search Results for

    Show / Hide Table of Contents

    Interface IDependencyLoopChecker<T>

    Runs through a set of objects, checking that no referencial loop exists between them.

    Usage: 1. Create new DependencyLoopChecker<T> 2. Provide a mapping function as above 3. Call AddDependency(T) for each item you need to check 4. Call HasLoop() - returns true if you have a loop. 5. Call PrintLooped() to get a message and the list of offending objects. 6. Call Reset() to clear the internal state, to reuse.

    Given the following example class:

    private class TestLinkedObject
    {
        public Guid EntityTypeID { get; set; }
        public Guid NewEntityTypeID { get; set; } 
        public override string ToString() => Name;
    }

    LoopChecker will then generate a wrapper (DependencyLoopItem<T>) for each object that you add via AddDependency(T).

    You must provide a lambda for how to map your object to DependencyLoopItem<T>. Given the above code, usage would look like this:

    var loopChecker = new DependencyLoopChecker{TestLinkedObject}
    (
        x => new DependencyItem{TestLinkedObject}
        {
            From = x.EntityTypeID,
            To = x.NewEntityTypeID,
            Item = x
        }
    );
    Namespace: LemonEdge.Utils
    Assembly: LemonEdge.Utils.dll
    Syntax
    public interface IDependencyLoopChecker<T>
    Type Parameters
    Name Description
    T

    The type of the Item you would like to check for loops

    Remarks

    Note: This checker breaks on the first instance of a loop found. You should identify those, Reset() and repeat the process with the remaining.

    Methods

    AddDependency(T)

    Adds an item to the internal list for checking.

    Declaration
    void AddDependency(T item)
    Parameters
    Type Name Description
    T item

    Your item

    HasLoop()

    Checks all items added via AddDependency(T), and breaks at the first loop that is found.

    Declaration
    bool HasLoop()
    Returns
    Type Description
    bool

    Whether a loop was found

    PrintLooped()

    Prints out the results found after calling HasLoop().

    Declaration
    (string Output, T?[] Looped) PrintLooped()
    Returns
    Type Description
    (string Output, T[] Looped)

    A string output of the first loop found, and the list of items.

    RemoveLooped()

    Removes the looping items discovered by calling HasLoop(). HasLoop() breaks at the first loop found. Use this to remove that first round of items, then repeat.

    Declaration
    T?[] RemoveLooped()
    Returns
    Type Description
    T[]

    The removed items

    Reset()

    Resets the internal lists for reuse.

    Declaration
    void Reset()

    Extension Methods

    LinqExtensions.AsArray<T>(T)
    LinqExtensions.ToArrayOfOne<T>(T)
    LinqExtensions.ToListOfOne<T>(T)
    MiscExtensions.SetIfNotEqual<T, TP>(T, Expression<Func<T, TP>>, TP)
    WeakReferenceExtensions.WeakReference(object)
    SQLExtensions.ToSQLValue(object, bool)
    ReflectionExtensions.ClearEventInvocations(object, string)
    StringExtensions.ToCSVFormatString(object, Type)
    In this article
    Back to top © LemonEdge Technologies. All rights reserved.