Skip to content

Game.Debug.ExtensionsHelpers

Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 mod/game code; this class is included in the main game assembly)

Namespace: Game.Debug

Type: public static class

Base: System.Object

Summary: Utility extension methods for ObservableList to allow adding or removing multiple items using IEnumerable. These methods simplify batch operations on ObservableList by forwarding individual Add/Remove calls for each element in the provided enumerable. They are intended for use in debug/tools code and rely on the ObservableList API (Add and Remove methods).


Fields

  • None.
    This is a static helper class and does not define instance fields.

Properties

  • None.
    No properties are defined by this class.

Constructors

  • None (static class).
    As a static class, there are no public constructors or instance initializers.

Methods

  • public static void Add<T>(this ObservableList<T> list, IEnumerable<T> items)
    Adds each element from the provided IEnumerable to the ObservableList by calling list.Add(item) for every item. If items is null, this method will simply do nothing (no exception is thrown). Use this to append multiple items in one call instead of iterating externally.

Additional notes: - Complexity is O(n) in the number of items in the enumerable (plus whatever cost ObservableList.Add has). - If ObservableList raises change notifications, each Add will typically trigger those notifications per item. - The method assumes list is not null; calling it with a null list will throw a NullReferenceException.

  • public static int Remove<T>(this ObservableList<T> list, IEnumerable<T> items)
    Removes each element in the provided IEnumerable from the ObservableList by calling list.Remove(item). The method counts and returns the number of successful removals (i.e., number of times list.Remove(item) returned true). If items is null, the method returns 0.

Additional notes: - Return value: integer count of removed items. - Complexity is O(n) in the number of items in the enumerable (plus whatever cost ObservableList.Remove has). - If ObservableList.Remove returns a boolean indicating success, this method sums those booleans to compute the returned count. - As with Add, calling this with a null list will throw a NullReferenceException. - Be careful if the enumerable comes from the same list (modifying a collection while enumerating it can cause issues depending on the enumerable's origin).

Usage Example

using System.Collections.Generic;
using Game.Debug;

// Example usage of ExtensionsHelpers:
void Example()
{
    var list = new ObservableList<string>();
    list.Add("existing");

    // Add multiple items at once
    IEnumerable<string> toAdd = new[] { "apple", "banana", "cherry" };
    list.Add(toAdd);

    // Remove multiple items at once; returns how many were removed
    IEnumerable<string> toRemove = new[] { "banana", "nonexistent" };
    int removedCount = list.Remove(toRemove); // removedCount == 1
}

Notes and cautions: - These are extension methods; ensure the namespace Game.Debug is in scope (via using Game.Debug) to call them as instance-style methods (list.Add(items)). - Because each element is added/removed individually, any side-effects or notifications raised by ObservableList will occur per element. If you need atomic batch semantics, use a collection API that supports batch operations or temporarily suppress notifications if supported.