15
15
using ReactiveUI . Validation . ValidationBindings ;
16
16
using Splat ;
17
17
18
- // ReSharper disable once CheckNamespace
19
18
namespace ReactiveUI . Validation . Extensions ;
20
19
21
20
/// <summary>
@@ -40,7 +39,6 @@ public static class ViewForExtensions
40
39
/// IValidationTextFormatter<string> into Splat.Locator.
41
40
/// </param>
42
41
/// <returns>Returns a <see cref="IDisposable"/> object.</returns>
43
- [ SuppressMessage ( "Design" , "CA1801: Parameter unused" , Justification = "Used for generic resolution." ) ]
44
42
public static IDisposable BindValidation < TView , TViewModel , TViewModelProperty > (
45
43
this TView view ,
46
44
TViewModel ? viewModel ,
@@ -50,74 +48,11 @@ public static IDisposable BindValidation<TView, TViewModel, TViewModelProperty>(
50
48
where TView : IViewFor < TViewModel >
51
49
where TViewModel : class , IReactiveObject , IValidatableViewModel
52
50
{
53
- if ( view is null )
54
- {
55
- throw new ArgumentNullException ( nameof ( view ) ) ;
56
- }
51
+ ArgumentNullException . ThrowIfNull ( view ) ;
57
52
58
- if ( viewModelProperty is null )
59
- {
60
- throw new ArgumentNullException ( nameof ( viewModelProperty ) ) ;
61
- }
53
+ ArgumentNullException . ThrowIfNull ( viewModelProperty ) ;
62
54
63
- if ( viewProperty is null )
64
- {
65
- throw new ArgumentNullException ( nameof ( viewProperty ) ) ;
66
- }
67
-
68
- formatter ??= Locator . Current . GetService < IValidationTextFormatter < string > > ( ) ??
69
- SingleLineFormatter . Default ;
70
-
71
- return ValidationBinding . ForProperty (
72
- view ,
73
- viewModelProperty ,
74
- ( _ , errors ) => viewProperty . Error = errors . FirstOrDefault ( msg => ! string . IsNullOrEmpty ( msg ) ) ,
75
- formatter ) ;
76
- }
77
-
78
- /// <summary>
79
- /// Platform binding to the TextInputLayout.
80
- /// </summary>
81
- /// <remarks>Supports multiple validations for the same property.</remarks>
82
- /// <typeparam name="TView">IViewFor of TViewModel.</typeparam>
83
- /// <typeparam name="TViewModel">ViewModel type.</typeparam>
84
- /// <typeparam name="TViewModelProperty">ViewModel property type.</typeparam>
85
- /// <param name="view">IViewFor instance.</param>
86
- /// <param name="viewModel">ViewModel instance. Can be null, used for generic type resolution.</param>
87
- /// <param name="viewModelProperty">ViewModel property.</param>
88
- /// <param name="viewProperty">View property to bind the validation message.</param>
89
- /// <param name="formatter">
90
- /// Validation formatter. Defaults to <see cref="SingleLineFormatter"/>. In order to override the global
91
- /// default value, implement <see cref="IValidationTextFormatter{TOut}"/> and register an instance of
92
- /// IValidationTextFormatter<string> into Splat.Locator.
93
- /// </param>
94
- /// <returns>Returns a <see cref="IDisposable"/> object.</returns>
95
- [ ExcludeFromCodeCoverage ]
96
- [ Obsolete ( "This method is no longer required, BindValidation now supports multiple validations." ) ]
97
- [ SuppressMessage ( "Design" , "CA1801: Parameter unused" , Justification = "Used for generic resolution." ) ]
98
- public static IDisposable BindValidationEx < TView , TViewModel , TViewModelProperty > (
99
- this TView view ,
100
- TViewModel ? viewModel ,
101
- Expression < Func < TViewModel , TViewModelProperty ? > > viewModelProperty ,
102
- TextInputLayout viewProperty ,
103
- IValidationTextFormatter < string > ? formatter = null )
104
- where TView : IViewFor < TViewModel >
105
- where TViewModel : class , IReactiveObject , IValidatableViewModel
106
- {
107
- if ( view is null )
108
- {
109
- throw new ArgumentNullException ( nameof ( view ) ) ;
110
- }
111
-
112
- if ( viewModelProperty is null )
113
- {
114
- throw new ArgumentNullException ( nameof ( viewModelProperty ) ) ;
115
- }
116
-
117
- if ( viewProperty is null )
118
- {
119
- throw new ArgumentNullException ( nameof ( viewProperty ) ) ;
120
- }
55
+ ArgumentNullException . ThrowIfNull ( viewProperty ) ;
121
56
122
57
formatter ??= Locator . Current . GetService < IValidationTextFormatter < string > > ( ) ??
123
58
SingleLineFormatter . Default ;
@@ -144,7 +79,6 @@ public static IDisposable BindValidationEx<TView, TViewModel, TViewModelProperty
144
79
/// IValidationTextFormatter<string> into Splat.Locator.
145
80
/// </param>
146
81
/// <returns>Returns a <see cref="IDisposable"/> object.</returns>
147
- [ SuppressMessage ( "Design" , "CA1801: Parameter unused" , Justification = "Used for generic resolution." ) ]
148
82
public static IDisposable BindValidation < TView , TViewModel > (
149
83
this TView view ,
150
84
TViewModel ? viewModel ,
@@ -154,20 +88,11 @@ public static IDisposable BindValidation<TView, TViewModel>(
154
88
where TView : IViewFor < TViewModel >
155
89
where TViewModel : class , IReactiveObject , IValidatableViewModel
156
90
{
157
- if ( view is null )
158
- {
159
- throw new ArgumentNullException ( nameof ( view ) ) ;
160
- }
91
+ ArgumentNullException . ThrowIfNull ( view ) ;
161
92
162
- if ( viewModelHelperProperty is null )
163
- {
164
- throw new ArgumentNullException ( nameof ( viewModelHelperProperty ) ) ;
165
- }
93
+ ArgumentNullException . ThrowIfNull ( viewModelHelperProperty ) ;
166
94
167
- if ( viewProperty is null )
168
- {
169
- throw new ArgumentNullException ( nameof ( viewProperty ) ) ;
170
- }
95
+ ArgumentNullException . ThrowIfNull ( viewProperty ) ;
171
96
172
97
formatter ??= Locator . Current . GetService < IValidationTextFormatter < string > > ( ) ??
173
98
SingleLineFormatter . Default ;
0 commit comments