Table of Contents

Class InvalidationManager

Namespace
SharpConsoleUI.Core
Assembly
SharpConsoleUI.dll

Thread-safe invalidation manager that coordinates all invalidation requests. Implements singleton pattern and batches rapid invalidation requests for efficiency.

public class InvalidationManager
Inheritance
InvalidationManager
Inherited Members

Properties

Instance

Gets the singleton instance of the InvalidationManager.

public static InvalidationManager Instance { get; }

Property Value

InvalidationManager

LogService

Optional log service for error logging. Can be set by ConsoleWindowSystem or tests.

public ILogService? LogService { get; set; }

Property Value

ILogService

Methods

GetCacheState(IWindowControl)

Gets or creates the cache state for a control.

public CacheState GetCacheState(IWindowControl control)

Parameters

control IWindowControl

The control whose cache state to retrieve.

Returns

CacheState

The cache state for the control.

GetContainerChildren(IContainer)

Gets all direct children of a container.

public IEnumerable<IWindowControl> GetContainerChildren(IContainer container)

Parameters

container IContainer

The container whose children to retrieve.

Returns

IEnumerable<IWindowControl>

A copy of the children collection to avoid concurrent modification issues.

IsChildOfContainer(IWindowControl, IContainer)

Checks if a control is a direct child of the specified container.

public bool IsChildOfContainer(IWindowControl control, IContainer container)

Parameters

control IWindowControl

The control to check.

container IContainer

The container to check against.

Returns

bool

true if the control is a direct child of the container; otherwise, false.

NeedsRendering(IWindowControl)

Checks if a control needs rendering (is invalid and not currently being rendered).

public bool NeedsRendering(IWindowControl control)

Parameters

control IWindowControl

The control to check.

Returns

bool

true if the control needs rendering; otherwise, false.

RegisterControl(IWindowControl)

Registers a control with the invalidation manager

public void RegisterControl(IWindowControl control)

Parameters

control IWindowControl

RegisterControlHierarchy(IWindowControl, IContainer)

Registers the parent-child relationship for hierarchy tracking. Used to propagate invalidation to parent containers.

public void RegisterControlHierarchy(IWindowControl child, IContainer parent)

Parameters

child IWindowControl

The child control.

parent IContainer

The parent container.

RequestInvalidation(IWindowControl, InvalidationReason, bool)

Requests invalidation for a control. The request is queued and processed in batches.

public void RequestInvalidation(IWindowControl control, InvalidationReason reason, bool propagateToParent = true)

Parameters

control IWindowControl

The control to invalidate.

reason InvalidationReason

The reason for invalidation.

propagateToParent bool

Whether to propagate the invalidation to the parent container. Defaults to true.

UnregisterControl(IWindowControl)

Unregisters a control from the invalidation manager

public void UnregisterControl(IWindowControl control)

Parameters

control IWindowControl

UnregisterControlHierarchy(IWindowControl)

Unregisters a control from its parent container in the hierarchy tracking.

public void UnregisterControlHierarchy(IWindowControl child)

Parameters

child IWindowControl

The child control to unregister.

WithCacheProtection<T>(IWindowControl, Func<T>, T)

Safely executes a render function with cache protection. Prevents concurrent rendering and handles invalidation on failure.

public T WithCacheProtection<T>(IWindowControl control, Func<T> renderFunction, T fallbackValue = default)

Parameters

control IWindowControl

The control being rendered.

renderFunction Func<T>

The function that produces the rendered content.

fallbackValue T

The value to return if another render is in progress. Defaults to default(T).

Returns

T

The rendered content, or the fallback value if rendering could not proceed.

Type Parameters

T

The type of the render result.