15
15
using ReactiveUI . Validation . ValidationBindings ;
16
16
using Splat ;
17
17
18
+ // ReSharper disable once CheckNamespace
18
19
namespace ReactiveUI . Validation . Extensions
19
20
{
20
21
/// <summary>
@@ -30,7 +31,7 @@ public static class ViewForExtensions
30
31
/// <typeparam name="TViewModel">ViewModel type.</typeparam>
31
32
/// <typeparam name="TViewModelProperty">ViewModel property type.</typeparam>
32
33
/// <param name="view">IViewFor instance.</param>
33
- /// <param name="viewModel">ViewModel instance.</param>
34
+ /// <param name="viewModel">ViewModel instance. Can be null, used for generic type resolution. </param>
34
35
/// <param name="viewModelProperty">ViewModel property.</param>
35
36
/// <param name="viewProperty">View property to bind the validation message.</param>
36
37
/// <param name="formatter">
@@ -42,13 +43,28 @@ public static class ViewForExtensions
42
43
[ SuppressMessage ( "Design" , "CA1801: Parameter unused" , Justification = "Used for generic resolution." ) ]
43
44
public static IDisposable BindValidation < TView , TViewModel , TViewModelProperty > (
44
45
this TView view ,
45
- TViewModel viewModel ,
46
+ TViewModel ? viewModel ,
46
47
Expression < Func < TViewModel , TViewModelProperty > > viewModelProperty ,
47
48
TextInputLayout viewProperty ,
48
49
IValidationTextFormatter < string > ? formatter = null )
49
50
where TView : IViewFor < TViewModel >
50
51
where TViewModel : class , IReactiveObject , IValidatableViewModel
51
52
{
53
+ if ( view is null )
54
+ {
55
+ throw new ArgumentNullException ( nameof ( view ) ) ;
56
+ }
57
+
58
+ if ( viewModelProperty is null )
59
+ {
60
+ throw new ArgumentNullException ( nameof ( viewModelProperty ) ) ;
61
+ }
62
+
63
+ if ( viewProperty is null )
64
+ {
65
+ throw new ArgumentNullException ( nameof ( viewProperty ) ) ;
66
+ }
67
+
52
68
formatter ??= Locator . Current . GetService < IValidationTextFormatter < string > > ( ) ??
53
69
SingleLineFormatter . Default ;
54
70
@@ -67,7 +83,7 @@ public static IDisposable BindValidation<TView, TViewModel, TViewModelProperty>(
67
83
/// <typeparam name="TViewModel">ViewModel type.</typeparam>
68
84
/// <typeparam name="TViewModelProperty">ViewModel property type.</typeparam>
69
85
/// <param name="view">IViewFor instance.</param>
70
- /// <param name="viewModel">ViewModel instance.</param>
86
+ /// <param name="viewModel">ViewModel instance. Can be null, used for generic type resolution. </param>
71
87
/// <param name="viewModelProperty">ViewModel property.</param>
72
88
/// <param name="viewProperty">View property to bind the validation message.</param>
73
89
/// <param name="formatter">
@@ -81,13 +97,28 @@ public static IDisposable BindValidation<TView, TViewModel, TViewModelProperty>(
81
97
[ SuppressMessage ( "Design" , "CA1801: Parameter unused" , Justification = "Used for generic resolution." ) ]
82
98
public static IDisposable BindValidationEx < TView , TViewModel , TViewModelProperty > (
83
99
this TView view ,
84
- TViewModel viewModel ,
100
+ TViewModel ? viewModel ,
85
101
Expression < Func < TViewModel , TViewModelProperty > > viewModelProperty ,
86
102
TextInputLayout viewProperty ,
87
103
IValidationTextFormatter < string > ? formatter = null )
88
104
where TView : IViewFor < TViewModel >
89
105
where TViewModel : class , IReactiveObject , IValidatableViewModel
90
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
+ }
121
+
91
122
formatter ??= Locator . Current . GetService < IValidationTextFormatter < string > > ( ) ??
92
123
SingleLineFormatter . Default ;
93
124
@@ -104,7 +135,7 @@ public static IDisposable BindValidationEx<TView, TViewModel, TViewModelProperty
104
135
/// <typeparam name="TView">IViewFor of TViewModel.</typeparam>
105
136
/// <typeparam name="TViewModel">ViewModel type.</typeparam>
106
137
/// <param name="view">IViewFor instance.</param>
107
- /// <param name="viewModel">ViewModel instance.</param>
138
+ /// <param name="viewModel">ViewModel instance. Can be null, used for generic type resolution. </param>
108
139
/// <param name="viewModelHelperProperty">ViewModel's ValidationHelper property.</param>
109
140
/// <param name="viewProperty">View property to bind the validation message.</param>
110
141
/// <param name="formatter">
@@ -116,13 +147,28 @@ public static IDisposable BindValidationEx<TView, TViewModel, TViewModelProperty
116
147
[ SuppressMessage ( "Design" , "CA1801: Parameter unused" , Justification = "Used for generic resolution." ) ]
117
148
public static IDisposable BindValidation < TView , TViewModel > (
118
149
this TView view ,
119
- TViewModel viewModel ,
150
+ TViewModel ? viewModel ,
120
151
Expression < Func < TViewModel ? , ValidationHelper > > viewModelHelperProperty ,
121
152
TextInputLayout viewProperty ,
122
153
IValidationTextFormatter < string > ? formatter = null )
123
154
where TView : IViewFor < TViewModel >
124
155
where TViewModel : class , IReactiveObject , IValidatableViewModel
125
156
{
157
+ if ( view is null )
158
+ {
159
+ throw new ArgumentNullException ( nameof ( view ) ) ;
160
+ }
161
+
162
+ if ( viewModelHelperProperty is null )
163
+ {
164
+ throw new ArgumentNullException ( nameof ( viewModelHelperProperty ) ) ;
165
+ }
166
+
167
+ if ( viewProperty is null )
168
+ {
169
+ throw new ArgumentNullException ( nameof ( viewProperty ) ) ;
170
+ }
171
+
126
172
formatter ??= Locator . Current . GetService < IValidationTextFormatter < string > > ( ) ??
127
173
SingleLineFormatter . Default ;
128
174
0 commit comments