Level6Rogue.OrderEngine 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Level6Rogue.OrderEngine --version 1.0.4
                    
NuGet\Install-Package Level6Rogue.OrderEngine -Version 1.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Level6Rogue.OrderEngine" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Level6Rogue.OrderEngine" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Level6Rogue.OrderEngine" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Level6Rogue.OrderEngine --version 1.0.4
                    
#r "nuget: Level6Rogue.OrderEngine, 1.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Level6Rogue.OrderEngine@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Level6Rogue.OrderEngine&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Level6Rogue.OrderEngine&version=1.0.4
                    
Install as a Cake Tool

OrderEngine

NuGet

A flexible .NET library for ordering and organizing elements with support for relative positioning, groups, and hierarchical structures.

This project is a wip and I may change the API and features as I develop it.

Features

  • Relative Ordering - Position elements before or after other elements
  • Index-Based Ordering - Assign explicit priority indices to elements
  • Grouping - Organize elements into hierarchical groups with different display types
  • Cycle Detection - Automatically detects and reports circular dependencies
  • Multiple Build Modes - Optimized for either single or multiple build scenarios

Installation

Install via NuGet:

dotnet add package Level6Rogue.OrderEngine

NuGet: https://www.nuget.org/packages/Level6Rogue.OrderEngine/

Quick Start

using OrderEngine;

// Create an order engine
IOrderEngine engine = OrderEngine.Create();

// Add elements
engine.Add("Item1");
engine.Add("Item2");
engine.Add("Item3");

// Build and get the ordered output
List<Output> result = engine.Build();

Ordering Rules

No Rule (Insertion Order)

Elements without ordering rules maintain their insertion order:

engine.Add("First");
engine.Add("Second");
engine.Add("Third");
// Result: First, Second, Third

Before

Position an element before another element:

engine.Add("A");
engine.Add("B");
engine.Add("C", new Before("B"));
// Result: A, C, B

After

Position an element after another element:

engine.Add("A");
engine.Add("B");
engine.Add("C", new After("A"));
// Result: A, C, B

ByIndex

Assign explicit priority indices for fine-grained control:

engine.Add("Item1", new ByIndex(10));
engine.Add("Item2", new ByIndex(5));
engine.Add("Item3", new ByIndex(15));
// Result: Item2, Item1, Item3 (sorted by index)

Negative indices are supported and sort before positive indices:

engine.Add("A");
engine.Add("B", new ByIndex(-100));
// Result: B, A

Groups

Implicit Groups (Path-Based)

Create groups using path separators (/):

engine.Add("Settings/Audio/Volume");
engine.Add("Settings/Audio/Mute");
engine.Add("Settings/Video/Resolution");

Output structure:

GroupStart: Settings
  GroupStart: Audio
    Volume
    Mute
  GroupEnd: Audio
  GroupStart: Video
    Resolution
  GroupEnd: Video
GroupEnd: Settings

Explicit Groups

Create empty groups or specify group types:

engine.AddGroup(new Group("MyGroup"));
engine.AddGroup(new Group("FoldableGroup", GroupType.Foldout));
engine.AddGroup(new Group("HorizontalGroup", GroupType.Horizontal));

Group Types

Type Description
GroupType.Default Standard group container
GroupType.Foldout Collapsible group
GroupType.Horizontal Horizontal layout group

Build Modes

Choose the optimization strategy based on your usage pattern:

// For multiple Build() calls (with caching)
IOrderEngine engine = OrderEngineFactory.Create(BuildMode.MultipleBuild);

// For a single Build() call (minimal overhead)
IOrderEngine engine = OrderEngineFactory.Create(BuildMode.SingleBuild);
Mode Best For Characteristics
MultipleBuild Calling Build() multiple times after adding elements Caches lookups, faster subsequent builds
SingleBuild Adding elements once, calling Build() once No caching overhead, minimal memory

Output Types

The Build() method returns a list of Output objects:

Type Description
OutputElement A regular element
GroupStart Marks the beginning of a group
GroupEnd Marks the end of a group
foreach (var output in engine.Build())
{
    switch (output)
    {
        case GroupStart gs:
            Console.WriteLine($"Group Start: {gs.Name} ({gs.GroupType})");
            break;
        case GroupEnd ge:
            Console.WriteLine($"Group End: {ge.Name}");
            break;
        case OutputElement el:
            Console.WriteLine($"Element: {el.Name}");
            break;
    }
}

Updating Elements

Adding an element with the same name updates its ordering rule:

engine.Add("A");
engine.Add("B", new Before("A"));  // B is before A
engine.Add("B", new After("A"));   // B is now after A
// Result: A, B

Error Handling

Circular Dependencies

The engine detects and throws an exception for circular dependencies:

engine.Add("A", new Before("B"));
engine.Add("B", new Before("A"));
engine.Build(); // Throws exception: circular dependency detected

Invalid References

Referencing a non-existent element throws an exception:

engine.Add("A", new Before("NonExistent"));
engine.Build(); // Throws exception: target not found

API Reference

IOrderEngine Interface

public interface IOrderEngine
{
    void Add(Element element, OrderRule? orderRule = null);
    void AddGroup(Group group, OrderRule? orderRule = null);
    List<Output> Build();
}

Element

// Create explicitly
var element = new Element("MyElement");

// Or use implicit conversion from string
engine.Add("MyElement");

OrderRule Types

public abstract record OrderRule;
public record ByIndex(int Index) : OrderRule;
public record Before(string ElementName) : OrderRule;
public record After(string ElementName) : OrderRule;

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.8 98 4/24/2026
1.0.7 103 4/24/2026
1.0.6 102 4/24/2026
1.0.5 101 4/24/2026
1.0.4 104 4/23/2026
1.0.3 96 4/18/2026
1.0.2 88 4/18/2026
1.0.1 98 4/18/2026
1.0.0 104 4/18/2026