Skip to content

04 01 Overview

Cyberdyne Development edited this page Feb 9, 2026 · 3 revisions

TypeCollections Overview

TypeCollections are enhanced enums with O(1) lookups and rich behavior. They replace traditional enums with strongly-typed classes.

Key Benefits

  • O(1) lookups - Source-generated dictionaries by ID and name
  • No reflection - All lookup code generated at compile time
  • Rich behavior - Add properties and methods to each option
  • Type-safe - Compile-time validation
  • Polymorphism - Use properties instead of switch statements

Quick Example

From FilterOperators.cs:

// Access via static property (generated)
var equalOp = FilterOperators.Equal;
Console.WriteLine($"   FilterOperators.Equal: {equalOp.Name}");

// Access via lookup
var greaterThan = FilterOperators.ByName("GreaterThan");
Console.WriteLine($"   FilterOperators.ByName(\"GreaterThan\"): {greaterThan.Name}");

// Iterate all options
Console.WriteLine($"   All operators: {string.Join(", ", FilterOperators.All().Select(p => p.Name))}");

// Use behavior - no switch statements needed!
// Each operator knows how to generate SQL predicates, etc.

For TypeCollections with terminal state handling, see ExecutionStatuses:

From IExecutionStatus.cs:12-27:

public interface IExecutionStatus : ITypeOption<int, ExecutionStatusBase>
{
    bool IsTerminal { get; }
    bool IsSuccess { get; }
    bool IsFailure { get; }
    bool AllowsRetry { get; }
    bool AllowsResume { get; }
    bool IsInProgress { get; }
    bool HasWarnings { get; }
}

Pattern Components

Component Purpose
Interface (IPaymentMethod) Contract with behavior properties
Base class (PaymentMethodBase) Constructor parameters, get-only properties
Options (CashPayment, etc.) Concrete implementations
Collection (PaymentMethods) Source-generated lookups

Next Steps

Clone this wiki locally