| | | 1 | | namespace NexusLabs.Needlr.Injection.AssemblyOrdering; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Factory for creating assembly ordering configurations. |
| | | 5 | | /// </summary> |
| | | 6 | | public static class AssemblyOrder |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Creates a new assembly order builder. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <returns>A new builder instance.</returns> |
| | 14 | 12 | | public static AssemblyOrderBuilder Create() => new(); |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Creates an ordering configuration from a builder action. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <param name="configure">Action to configure the ordering rules.</param> |
| | | 18 | | /// <returns>The configured builder.</returns> |
| | | 19 | | public static AssemblyOrderBuilder Create(Action<AssemblyOrderBuilder> configure) |
| | | 20 | | { |
| | 2 | 21 | | ArgumentNullException.ThrowIfNull(configure); |
| | 1 | 22 | | var builder = new AssemblyOrderBuilder(); |
| | 1 | 23 | | configure(builder); |
| | 1 | 24 | | return builder; |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Creates a preset ordering: libraries first, then executables, tests last. |
| | | 29 | | /// Uses file location to distinguish DLLs from EXEs. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <returns>A builder configured with lib-test-entry ordering.</returns> |
| | | 32 | | public static AssemblyOrderBuilder LibTestEntry() => |
| | 5 | 33 | | Create() |
| | 5 | 34 | | .By(a => a.Location.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) |
| | 5 | 35 | | && !a.Name.Contains("Tests", StringComparison.OrdinalIgnoreCase)) |
| | 5 | 36 | | .ThenBy(a => a.Location.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) |
| | 5 | 37 | | .ThenBy(a => a.Name.Contains("Tests", StringComparison.OrdinalIgnoreCase)); |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Creates a preset ordering: non-test assemblies first, tests last. |
| | | 41 | | /// Use this for source-gen scenarios where only assembly names are available. |
| | | 42 | | /// </summary> |
| | | 43 | | /// <returns>A builder configured with tests-last ordering by name.</returns> |
| | | 44 | | public static AssemblyOrderBuilder TestsLast() => |
| | 6 | 45 | | Create() |
| | 6 | 46 | | .By(a => !a.Name.Contains("Tests", StringComparison.OrdinalIgnoreCase)) |
| | 6 | 47 | | .ThenBy(a => a.Name.Contains("Tests", StringComparison.OrdinalIgnoreCase)); |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Creates a preset ordering: alphabetical by name. |
| | | 51 | | /// </summary> |
| | | 52 | | /// <returns>A builder configured with alphabetical ordering.</returns> |
| | | 53 | | public static AssemblyOrderBuilder Alphabetical() => |
| | 2 | 54 | | Create() |
| | 2 | 55 | | .By(a => true); // All assemblies match, sorted alphabetically within tier |
| | | 56 | | } |