ObservableObjectBaseGetT(FuncT, String) Method

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.

Definition

Namespace: KGySoft.ComponentModel
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0-preview.1
C#
protected T Get<T>(
	Func<T> createInitialValue,
	string propertyName = null
)

Parameters

createInitialValue  FuncT
A delegate, which creates the initial value if the property does not exist. If , then an exception is thrown for an uninitialized property.
propertyName  String  (Optional)
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

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

Exceptions

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.
ObjectDisposedExceptionIsDisposed returns whereas AllowReadingDisposedObject returns .

See Also