Skip to content

},System.Func{--1,System.Boolean},System.String)} },System.Func{--1,System.Boolean},System.Func{--1,System.String})} ,System.String)} ,System.Func{--1,System.Boolean},System.Func{--1,System.String})} )} )} },System.IObservable{System.Boolean},System.String)} },System.IObservable{--2},System.Func{--2,System.Boolean},System.Func{--2,System.String})} },System.IObservable{ReactiveUI.Validation.States.IValidationState})} },System.IObservable{--2})}

ValidatableViewModelExtensions.ValidationRule(TViewModel, Expression>, Func, string) method

Defined in

Type: ValidatableViewModelExtensions Namespace: ReactiveUI.Validation.Extensions Assembly: ReactiveUI.Validation.dll

Applies to

net10.0, net10.0-tvos26.0, net10.0-maccatalyst26.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net10.0-macos26.0, net10.0-windows10.0.19041, net10.0-ios26.0, net10.0-android36.0, net9.0, net9.0-windows10.0.19041, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-macos14.2, net8.0-maccatalyst17.5, net8.0-ios17.5, net8.0-tvos17.2, net8.0-windows10.0.19041, net8.0-macos14.5, netstandard2.1, net481, net462, net471

Overloads

  • 1. public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp?>> viewModelProperty, Func<TViewModelProp?, bool> isPropertyValid, string message) where TViewModel : IReactiveObject, IValidatableViewModel
  • 2. public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp?>> viewModelProperty, Func<TViewModelProp?, bool> isPropertyValid, Func<TViewModelProp?, string> message) where TViewModel : IReactiveObject, IValidatableViewModel
  • 3. public static ValidationHelper ValidationRule<TViewModel>(this TViewModel viewModel, IObservable<bool> validationObservable, string message) where TViewModel : IReactiveObject, IValidatableViewModel
  • 4. public static ValidationHelper ValidationRule<TViewModel, TValue>(this TViewModel viewModel, IObservable<TValue> validationObservable, Func<TValue, bool> isValidFunc, Func<TValue, string> messageFunc) where TViewModel : IReactiveObject, IValidatableViewModel
  • 5. public static ValidationHelper ValidationRule<TViewModel>(this TViewModel viewModel, IObservable<IValidationState> validationObservable) where TViewModel : IReactiveObject, IValidatableViewModel
  • 6. public static ValidationHelper ValidationRule<TViewModel, TValue>(this TViewModel viewModel, IObservable<TValue> validationObservable) where TViewModel : IReactiveObject, IValidatableViewModel where TValue : IValidationState
  • 7. public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp>> viewModelProperty, IObservable<bool> viewModelObservable, string message) where TViewModel : IReactiveObject, IValidatableViewModel
  • 8. public static ValidationHelper ValidationRule<TViewModel, TViewModelProp, TValue>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp>> viewModelProperty, IObservable<TValue> viewModelObservable, Func<TValue, bool> isValidFunc, Func<TValue, string> messageFunc) where TViewModel : IReactiveObject, IValidatableViewModel
  • 9. public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp>> viewModelProperty, IObservable<IValidationState> validationObservable) where TViewModel : IReactiveObject, IValidatableViewModel
  • 10. public static ValidationHelper ValidationRule<TViewModel, TViewModelProp, TValue>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp>> viewModelProperty, IObservable<TValue> validationObservable) where TViewModel : IReactiveObject, IValidatableViewModel where TValue : IValidationState

1. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp?>> viewModelProperty, Func<TViewModelProp?, bool> isPropertyValid, string message) where TViewModel : IReactiveObject, IValidatableViewModel

View source

Summary: Setup a validation rule for a specified ViewModel property with static error message.

Type parameters

NameDescription
TViewModelViewModel type.
TViewModelPropViewModel property type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
viewModelPropertyExpression>ViewModel property.
isPropertyValidFuncFunc to define if the viewModelProperty is valid or not.
messagestringValidation error message.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel, viewModelProperty, isPropertyValid, or message is null or empty.

2. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp?>> viewModelProperty, Func<TViewModelProp?, bool> isPropertyValid, Func<TViewModelProp?, string> message) where TViewModel : IReactiveObject, IValidatableViewModel

View source

Summary: Setup a validation rule for a specified ViewModel property with dynamic error message.

Type parameters

NameDescription
TViewModelViewModel type.
TViewModelPropViewModel property type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
viewModelPropertyExpression>ViewModel property.
isPropertyValidFuncFunc to define if the viewModelProperty is valid or not.
messageFuncFunc to define the validation error message based on the viewModelProperty value.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel, viewModelProperty, isPropertyValid, or message is null.

3. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel>(this TViewModel viewModel, IObservable<bool> validationObservable, string message) where TViewModel : IReactiveObject, IValidatableViewModel

View source

Summary: Setup a validation rule with a general observable indicating validity and a static error message.

Type parameters

NameDescription
TViewModelViewModel type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
validationObservableIObservableObservable to define if the viewModel is valid or not.
messagestringValidation error message.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Remarks

        It should be noted that the observable should provide an initial value, otherwise that can result
        in an inconsistent performance.
        

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel, validationObservable, or message is null.

4. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel, TValue>(this TViewModel viewModel, IObservable<TValue> validationObservable, Func<TValue, bool> isValidFunc, Func<TValue, string> messageFunc) where TViewModel : IReactiveObject, IValidatableViewModel

View source

Summary: Setup a validation rule with a general observable indicating validity with a dynamic validation function and a dynamic context-aware error message.

Type parameters

NameDescription
TViewModelViewModel type.
TValueValidation observable type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
validationObservableIObservableObservable to define if the viewModel is valid or not.
isValidFuncFuncFunc to define if the value emitted by the observable is valid.
messageFuncFuncFunc to define the validation error message based on the observable value.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Remarks

        It should be noted that the observable should provide an initial value, otherwise that can result
        in an inconsistent performance.
        

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel, validationObservable, isValidFunc, or messageFunc is null.

5. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel>(this TViewModel viewModel, IObservable<IValidationState> validationObservable) where TViewModel : IReactiveObject, IValidatableViewModel

View source

Summary: Setup a validation rule with a general observable based on IValidationState.

Type parameters

NameDescription
TViewModelViewModel type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
validationObservableIObservableObservable to define if the viewModel is valid or not.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Remarks

        It should be noted that the observable should provide an initial value, otherwise that can result
        in an inconsistent performance.
        

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel or validationObservable is null.

6. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel, TValue>(this TViewModel viewModel, IObservable<TValue> validationObservable) where TViewModel : IReactiveObject, IValidatableViewModel where TValue : IValidationState

View source

Summary: Setup a validation rule with a general observable based on IValidationState.

Type parameters

NameDescription
TViewModelViewModel type.
TValueValidation observable type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
validationObservableIObservableObservable to define if the viewModel is valid or not.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Remarks

        It should be noted that the observable should provide an initial value, otherwise that can result
        in an inconsistent performance.
        

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel or validationObservable is null.

7. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp>> viewModelProperty, IObservable<bool> viewModelObservable, string message) where TViewModel : IReactiveObject, IValidatableViewModel

View source

Summary: Setup a validation rule with a general observable indicating validity and a static error message for the given view model property.

Type parameters

NameDescription
TViewModelViewModel type.
TViewModelPropViewModel property type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
viewModelPropertyExpression>ViewModel property referenced in viewModelObservableProperty.
viewModelObservableIObservableObservable to define if the viewModel is valid or not.
messagestringValidation error message.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Remarks

        It should be noted that the observable should provide an initial value, otherwise that can result
        in an inconsistent performance.
        

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel, viewModelProperty, viewModelObservable, or message is null.

8. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel, TViewModelProp, TValue>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp>> viewModelProperty, IObservable<TValue> viewModelObservable, Func<TValue, bool> isValidFunc, Func<TValue, string> messageFunc) where TViewModel : IReactiveObject, IValidatableViewModel

View source

Summary: Setup a validation rule with a general observable indicating validity with a dynamic validation function and a dynamic context-aware error message for the given view model property.

Type parameters

NameDescription
TViewModelViewModel type.
TViewModelPropViewModel property type.
TValueValidation observable type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
viewModelPropertyExpression>ViewModel property referenced in viewModelObservableProperty.
viewModelObservableIObservableObservable to define if the viewModel is valid or not.
isValidFuncFuncFunc to define if the value emitted by the observable is valid.
messageFuncFuncFunc to define the validation error message based on the observable value.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Remarks

        It should be noted that the observable should provide an initial value, otherwise that can result
        in an inconsistent performance.
        

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel, viewModelProperty, viewModelObservable, isValidFunc, or messageFunc is null.

9. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp>> viewModelProperty, IObservable<IValidationState> validationObservable) where TViewModel : IReactiveObject, IValidatableViewModel

View source

Summary: Setup a validation rule with a general observable based on IValidationState.

Type parameters

NameDescription
TViewModelViewModel type.
TViewModelPropViewModel property type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
viewModelPropertyExpression>ViewModel property referenced in viewModelObservableProperty.
validationObservableIObservableObservable to define if the viewModel is valid or not.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Remarks

        It should be noted that the observable should provide an initial value, otherwise that can result
        in an inconsistent performance.
        

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel, viewModelProperty, or validationObservable is null.

10. Overload

Attributes: [RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")] [RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]

public static ValidationHelper ValidationRule<TViewModel, TViewModelProp, TValue>(this TViewModel viewModel, Expression<Func<TViewModel, TViewModelProp>> viewModelProperty, IObservable<TValue> validationObservable) where TViewModel : IReactiveObject, IValidatableViewModel where TValue : IValidationState

View source

Summary: Setup a validation rule with a general observable based on IValidationState.

Type parameters

NameDescription
TViewModelViewModel type.
TViewModelPropViewModel property type.
TValueValidation observable type.

Parameters

NameTypeDescription
viewModelTViewModelViewModel instance.
viewModelPropertyExpression>ViewModel property referenced in viewModelObservableProperty.
validationObservableIObservableObservable to define if the viewModel is valid or not.

Returns: ValidationHelper -- Returns a ValidationHelper object.

Remarks

        It should be noted that the observable should provide an initial value, otherwise that can result
        in an inconsistent performance.
        

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown when viewModel, viewModelProperty, or validationObservable is null.