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
LogService
Optional log service for error logging. Can be set by ConsoleWindowSystem or tests.
public ILogService? LogService { get; set; }
Property Value
Methods
GetCacheState(IWindowControl)
Gets or creates the cache state for a control.
public CacheState GetCacheState(IWindowControl control)
Parameters
controlIWindowControlThe 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
containerIContainerThe 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
controlIWindowControlThe control to check.
containerIContainerThe container to check against.
Returns
- bool
trueif 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
controlIWindowControlThe control to check.
Returns
- bool
trueif the control needs rendering; otherwise,false.
RegisterControl(IWindowControl)
Registers a control with the invalidation manager
public void RegisterControl(IWindowControl control)
Parameters
controlIWindowControl
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
childIWindowControlThe child control.
parentIContainerThe 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
controlIWindowControlThe control to invalidate.
reasonInvalidationReasonThe reason for invalidation.
propagateToParentboolWhether 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
controlIWindowControl
UnregisterControlHierarchy(IWindowControl)
Unregisters a control from its parent container in the hierarchy tracking.
public void UnregisterControlHierarchy(IWindowControl child)
Parameters
childIWindowControlThe 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
controlIWindowControlThe control being rendered.
renderFunctionFunc<T>The function that produces the rendered content.
fallbackValueTThe 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
TThe type of the render result.