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
fieldboolReference to the boolean backing field
valueboolNew boolean value
containerIContainerContainer 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
fieldColor?Reference to the Color backing field
valueColor?New color value (null = use default/parent color)
containerIContainerContainer 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
fieldint?Reference to the Width/Height backing field
valueint?New dimension value (null = auto-size)
containerIContainerContainer 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
fieldTEnumReference to the enum backing field
valueTEnumNew enum value
containerIContainerContainer to invalidate if changed
Returns
- bool
True if value changed, false otherwise
Type Parameters
TEnumEnum 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
fieldTReference to the backing field
valueTNew value to set
containerIContainerContainer to invalidate (if value changed)
validateFunc<T, T>Optional validation function to transform/validate the value
invalidateboolWhether to invalidate container on change (default true)
Returns
- bool
True if value changed, false otherwise
Type Parameters
TProperty 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
fieldstringReference to the string backing field
valuestringNew string value
containerIContainerContainer to invalidate if changed
nullToEmptyboolIf true, converts null to empty string (default false)
Returns
- bool
True if value changed, false otherwise