 | BaseViewModel.TrySetValue<TValue> Method (TValue, Func<TValue, ValueTuple<Boolean, IEnumerable<String>>>, TValue, String, Boolean, Boolean) |
Sets the value of the referenced property and executes a validation delegate.
Namespace:
BionicCode.Utilities.Net.Standard.ViewModel
Assembly:
BionicCode.Utilities.Net.Standard (in BionicCode.Utilities.Net.Standard.dll) Version: 1.0.4
Syntaxprotected virtual bool TrySetValue<TValue>(
TValue value,
Func<TValue, (bool IsValid, IEnumerable<string> ErrorMessages)> validationDelegate,
ref TValue targetBackingField,
string propertyName = null,
bool isRejectInvalidValueEnabled = true,
bool isThrowExceptionOnValidationErrorEnabled = false
)
Protected Overridable Function TrySetValue(Of TValue) (
value As TValue,
validationDelegate As Func(Of TValue, (IsValid As Boolean, ErrorMessages As IEnumerable(Of String))),
ByRef targetBackingField As TValue,
Optional propertyName As String = Nothing,
Optional isRejectInvalidValueEnabled As Boolean = true,
Optional isThrowExceptionOnValidationErrorEnabled As Boolean = false
) As Boolean
Dim value As TValue
Dim validationDelegate As Func(Of TValue, (IsValid As Boolean, ErrorMessages As IEnumerable(Of String)))
Dim targetBackingField As TValue
Dim propertyName As String
Dim isRejectInvalidValueEnabled As Boolean
Dim isThrowExceptionOnValidationErrorEnabled As Boolean
Dim returnValue As Boolean
returnValue = Me.TrySetValue(value,
validationDelegate, targetBackingField,
propertyName, isRejectInvalidValueEnabled,
isThrowExceptionOnValidationErrorEnabled)
protected:
generic<typename TValue>
virtual bool TrySetValue(
TValue value,
Func<TValue, ValueTuple<bool, IEnumerable<String^>^>>^ validationDelegate,
TValue% targetBackingField,
String^ propertyName = nullptr,
bool isRejectInvalidValueEnabled = true,
bool isThrowExceptionOnValidationErrorEnabled = false
)
abstract TrySetValue :
value : 'TValue *
validationDelegate : Func<'TValue, ValueTuple<bool, IEnumerable<string>>> *
targetBackingField : 'TValue byref *
?propertyName : string *
?isRejectInvalidValueEnabled : bool *
?isThrowExceptionOnValidationErrorEnabled : bool
(* Defaults:
let _propertyName = defaultArg propertyName null
let _isRejectInvalidValueEnabled = defaultArg isRejectInvalidValueEnabled true
let _isThrowExceptionOnValidationErrorEnabled = defaultArg isThrowExceptionOnValidationErrorEnabled false
*)
-> bool
override TrySetValue :
value : 'TValue *
validationDelegate : Func<'TValue, ValueTuple<bool, IEnumerable<string>>> *
targetBackingField : 'TValue byref *
?propertyName : string *
?isRejectInvalidValueEnabled : bool *
?isThrowExceptionOnValidationErrorEnabled : bool
(* Defaults:
let _propertyName = defaultArg propertyName null
let _isRejectInvalidValueEnabled = defaultArg isRejectInvalidValueEnabled true
let _isThrowExceptionOnValidationErrorEnabled = defaultArg isThrowExceptionOnValidationErrorEnabled false
*)
-> bool
J# supports the use of generic APIs, but not the declaration of new ones.
JScript does not support generic types or methods.
JavaScript does not support generic types or methods.
PROTECTED VIRTUAL METHOD TrySetValue<TValue>(
value AS TValue,
validationDelegate AS Func<TValue, ValueTuple<LOGIC, IEnumerable<STRING>>>,
targetBackingField REF TValue,
propertyName AS STRING := NULL,
isRejectInvalidValueEnabled AS LOGIC := TRUE,
isThrowExceptionOnValidationErrorEnabled AS LOGIC := FALSE
)
AS LOGIC
Parameters
- value
- Type: TValue
The new value which is to be set to the property. - validationDelegate
- Type: System.Func<TValue, ValueTuple<Boolean, IEnumerable<String>>>
The callback that is used to validate the new value. - targetBackingField
- Type: TValue
The reference to the backing field. - propertyName (Optional)
- Type: System.String
The name of the property to set. Default name is the property that called this method. - isRejectInvalidValueEnabled (Optional)
- Type: System.Boolean
When true the invalid value is not stored to the backing field.
Use this to ensure that the view model in a valid state. - isThrowExceptionOnValidationErrorEnabled (Optional)
- Type: System.Boolean
Enable throwing an if validation failed. Use this when ValidatesOnExceptions on a Binding is set to true
Type Parameters
- TValue
- The generic value type parameter
Return Value
Type:
BooleanReturns
true if the new value doesn't equal the old value and the new value is valid. Returns
false if the new value equals the old value or the validation has failed.
Exceptions
RemarksThis property setter supports invalid value rejection, which means values are only assigned to the backing field if they are valid which is when the validationDelegate return true.
To support visual validation error feed back and proper behavior in TwoWay binding scenarios,
it is recommended to set isThrowExceptionOnValidationErrorEnabled to true and set the validation mode of the binding to Binding.ValidatesOnExceptions.
If not doing so, the binding target will clear the new value and show the last valid value instead.
See Also