Table of Contents

Class PropertySetterHelper

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Helper class for property setters with validation and invalidation. Eliminates 200-250 lines of duplicated Width/Height/Color property patterns across 14+ controls.

public static class PropertySetterHelper
Inheritance
PropertySetterHelper
Inherited Members

Methods

SetBoolProperty(ref bool, bool, IContainer?)

Sets a boolean property with automatic invalidation.

public static bool SetBoolProperty(ref bool field, bool value, IContainer? container)

Parameters

field bool

Reference to the boolean backing field

value bool

New boolean value

container IContainer

Container to invalidate if changed

Returns

bool

True if value changed, false otherwise

SetColorProperty(ref Color?, Color?, IContainer?)

Sets a nullable Color property with automatic invalidation.

public static bool SetColorProperty(ref Color? field, Color? value, IContainer? container)

Parameters

field Color?

Reference to the Color backing field

value Color?

New color value (null = use default/parent color)

container IContainer

Container to invalidate if changed

Returns

bool

True if value changed, false otherwise

SetDimensionProperty(ref int?, int?, IContainer?)

Sets a nullable integer dimension property (Width or Height) with validation. Ensures value is non-negative if provided.

public static bool SetDimensionProperty(ref int? field, int? value, IContainer? container)

Parameters

field int?

Reference to the Width/Height backing field

value int?

New dimension value (null = auto-size)

container IContainer

Container to invalidate if changed

Returns

bool

True if value changed, false otherwise

SetEnumProperty<TEnum>(ref TEnum, TEnum, IContainer?)

Sets an enum property with automatic invalidation.

public static bool SetEnumProperty<TEnum>(ref TEnum field, TEnum value, IContainer? container) where TEnum : struct, Enum

Parameters

field TEnum

Reference to the enum backing field

value TEnum

New enum value

container IContainer

Container to invalidate if changed

Returns

bool

True if value changed, false otherwise

Type Parameters

TEnum

Enum type

SetProperty<T>(ref T, T, IContainer?, Func<T, T>?, bool)

Sets a property value with optional validation and automatic container invalidation.

public static bool SetProperty<T>(ref T field, T value, IContainer? container, Func<T, T>? validate = null, bool invalidate = true)

Parameters

field T

Reference to the backing field

value T

New value to set

container IContainer

Container to invalidate (if value changed)

validate Func<T, T>

Optional validation function to transform/validate the value

invalidate bool

Whether to invalidate container on change (default true)

Returns

bool

True if value changed, false otherwise

Type Parameters

T

Property type

SetStringProperty(ref string, string, IContainer?, bool)

Sets a string property with automatic invalidation.

public static bool SetStringProperty(ref string field, string value, IContainer? container, bool nullToEmpty = false)

Parameters

field string

Reference to the string backing field

value string

New string value

container IContainer

Container to invalidate if changed

nullToEmpty bool

If true, converts null to empty string (default false)

Returns

bool

True if value changed, false otherwise