KGy SOFT

ObservableObjectBaseGetT Method (FuncT, String)

KGy SOFT Core Libraries Help
Gets the value of a property, or - if it was not set before -, then creates its initial value. The created initial value will be stored in the internal property storage without triggering the PropertyChanged event. For constant or simple expressions, or to return a default value for a non-existing property without storing it internally use the other Get overload.
For an example, see the Remarks section of the ObservableObjectBase class.

Namespace:  KGySoft.ComponentModel
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 5.4.0
Syntax

protected T Get<T>(
	Func<T> createInitialValue,
	string propertyName = null
)

Parameters

createInitialValue
Type: SystemFuncT
A delegate, which creates the initial value if the property does not exist. If , then an exception is thrown for an uninitialized property.
propertyName (Optional)
Type: SystemString
The name of the property to get. This parameter is optional.
Default value: The name of the caller member.

Type Parameters

T
The type of the property.

Return Value

Type: T
The value of the property, or the created initial value returned by the createInitialValue parameter.
Exceptions

ExceptionCondition
ArgumentNullExceptionpropertyName is .
InvalidOperationExceptionpropertyName cannot be retrieved.
-or-
The stored value of the property is not compatible with T.
-or-
propertyName value does not exist and createInitialValue is .
-or-
The created default value of the property cannot be set.
-or-
CanGetProperty is not overridden and propertyName is not an actual instance property in this instance.
See Also

Reference