Skip to content

Commit 1ea769f

Browse files
committed
Fix warnings
1 parent edd1caa commit 1ea769f

File tree

9 files changed

+128
-7
lines changed

9 files changed

+128
-7
lines changed

src/ReactiveUI.Validation.Tests/Models/SampleView.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class SampleView : IViewFor<ISampleViewModel>
2222
/// <summary>
2323
/// Gets or sets the view model of this particular view.
2424
/// </summary>
25-
public ISampleViewModel ViewModel { get; set; } = null!;
25+
public ISampleViewModel? ViewModel { get; set; }
2626
/// <summary>
2727
/// Gets or sets the name view property.
2828
/// </summary>
@@ -32,9 +32,9 @@ public class SampleView : IViewFor<ISampleViewModel>
3232
/// </summary>
3333
public string NameErrorLabel { get; set; } = null!;
3434
/// <inheritdoc />
35-
object IViewFor.ViewModel
35+
object? IViewFor.ViewModel
3636
{
3737
get => ViewModel;
38-
set => ViewModel = (ISampleViewModel)value;
38+
set => ViewModel = (ISampleViewModel?)value;
3939
}
40-
}
40+
}

src/ReactiveUI.Validation.Tests/ValidationBindingTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ public void ShouldSupportBindingToInterfaces()
576576
const string nameErrorMessage = "Name shouldn't be empty.";
577577
var view = new SampleView(new SampleViewModel());
578578

579-
view.ViewModel.ValidationRule(
579+
Assert.That(view.ViewModel, Is.Not.Null);
580+
view.ViewModel!.ValidationRule(
580581
viewModel => viewModel.Name,
581582
name => !string.IsNullOrWhiteSpace(name),
582583
nameErrorMessage);
@@ -813,7 +814,7 @@ public void ShouldBindValidationRuleEmittingValidationStates()
813814
var viewModelBlockedValidationState = isViewModelBlocked.Select(blocked =>
814815
(IValidationState)new CustomValidationState(!blocked, viewModelIsBlockedMessage));
815816

816-
view.ViewModel.ValidationRule(viewModelBlockedValidationState);
817+
view.ViewModel!.ValidationRule(viewModelBlockedValidationState);
817818

818819
view.Bind(view.ViewModel, x => x.Name, x => x.NameLabel);
819820
view.BindValidation(view.ViewModel, x => x.Name, x => x.NameErrorLabel);
@@ -863,7 +864,7 @@ public void ShouldBindValidationRuleEmittingValidationStatesGeneric()
863864
!string.IsNullOrWhiteSpace(name),
864865
nameErrorMessage)));
865866

866-
view.ViewModel.ValidationRule(
867+
view.ViewModel!.ValidationRule(
867868
isViewModelBlocked.Select(blocked =>
868869
new CustomValidationState(!blocked, viewModelIsBlockedMessage)));
869870

src/ReactiveUI.Validation/Components/BasePropertyValidation.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ public sealed class BasePropertyValidation<TViewModel, TViewModelProperty> : Bas
181181
/// <param name="viewModelProperty">ViewModel property.</param>
182182
/// <param name="isValidFunc">Func to define if the viewModelProperty is valid or not.</param>
183183
/// <param name="message">Validation error message.</param>
184+
#if NET6_0_OR_GREATER
185+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
186+
#endif
184187
public BasePropertyValidation(
185188
TViewModel viewModel,
186189
Expression<Func<TViewModel, TViewModelProperty?>> viewModelProperty,
@@ -197,6 +200,9 @@ public BasePropertyValidation(
197200
/// <param name="viewModelProperty">ViewModel property.</param>
198201
/// <param name="isValidFunc">Func to define if the viewModelProperty is valid or not.</param>
199202
/// <param name="message">Func to define the validation error message based on the viewModelProperty value.</param>
203+
#if NET6_0_OR_GREATER
204+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
205+
#endif
200206
public BasePropertyValidation(
201207
TViewModel viewModel,
202208
Expression<Func<TViewModel, TViewModelProperty?>> viewModelProperty,
@@ -214,6 +220,9 @@ public BasePropertyValidation(
214220
/// <param name="viewModelProperty">ViewModel property.</param>
215221
/// <param name="isValidFunc">Func to define if the viewModelProperty is valid or not.</param>
216222
/// <param name="messageFunc">Func to define the validation error message based on the viewModelProperty and isValidFunc values.</param>
223+
#if NET6_0_OR_GREATER
224+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
225+
#endif
217226
public BasePropertyValidation(
218227
TViewModel viewModel,
219228
Expression<Func<TViewModel, TViewModelProperty?>> viewModelProperty,
@@ -232,6 +241,10 @@ public BasePropertyValidation(
232241
/// <param name="viewModelProperty">ViewModel property.</param>
233242
/// <param name="isValidFunc">Func to define if the viewModelProperty is valid or not.</param>
234243
/// <param name="messageFunc">Func to define the validation error message based on the viewModelProperty and isValidFunc values.</param>
244+
#if NET6_0_OR_GREATER
245+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
246+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
247+
#endif
235248
private BasePropertyValidation(
236249
TViewModel viewModel,
237250
Expression<Func<TViewModel, TViewModelProperty?>> viewModelProperty,

src/ReactiveUI.Validation/Contexts/ValidationContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
using System;
77
using System.Buffers;
88
using System.Collections.Generic;
9+
using System.Diagnostics.CodeAnalysis;
910
using System.Linq;
1011
using System.Reactive.Concurrency;
1112
using System.Reactive.Disposables;
1213
using System.Reactive.Disposables.Fluent;
1314
using System.Reactive.Linq;
1415
using System.Reactive.Subjects;
16+
1517
using DynamicData;
18+
1619
using ReactiveUI.Validation.Collections;
1720
using ReactiveUI.Validation.Components.Abstractions;
1821
using ReactiveUI.Validation.States;
@@ -47,6 +50,9 @@ public class ValidationContext : ReactiveObject, IValidationContext
4750
/// Initializes a new instance of the <see cref="ValidationContext"/> class.
4851
/// </summary>
4952
/// <param name="scheduler">Optional scheduler to use for the properties. Uses the current thread scheduler by default.</param>
53+
#if NET6_0_OR_GREATER
54+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
55+
#endif
5056
public ValidationContext(IScheduler? scheduler = null)
5157
{
5258
scheduler ??= CurrentThreadScheduler.Instance;

src/ReactiveUI.Validation/Extensions/ValidatableViewModelExtensions.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
// See the LICENSE file in the project root for full license information.
55

66
using System;
7+
using System.Diagnostics.CodeAnalysis;
78
using System.Linq;
89
using System.Linq.Expressions;
910
using System.Reactive.Disposables;
1011
using System.Reactive.Linq;
12+
1113
using ReactiveUI.Validation.Abstractions;
1214
using ReactiveUI.Validation.Components;
1315
using ReactiveUI.Validation.Components.Abstractions;
@@ -32,6 +34,10 @@ public static class ValidatableViewModelExtensions
3234
/// <param name="isPropertyValid">Func to define if the viewModelProperty is valid or not.</param>
3335
/// <param name="message">Validation error message.</param>
3436
/// <returns>Returns a <see cref="ValidationHelper"/> object.</returns>
37+
#if NET6_0_OR_GREATER
38+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
39+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
40+
#endif
3541
public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(
3642
this TViewModel viewModel,
3743
Expression<Func<TViewModel, TViewModelProp?>> viewModelProperty,
@@ -76,6 +82,10 @@ public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(
7682
/// <param name="isPropertyValid">Func to define if the viewModelProperty is valid or not.</param>
7783
/// <param name="message">Func to define the validation error message based on the viewModelProperty value.</param>
7884
/// <returns>Returns a <see cref="ValidationHelper"/> object.</returns>
85+
#if NET6_0_OR_GREATER
86+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
87+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
88+
#endif
7989
public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(
8090
this TViewModel viewModel,
8191
Expression<Func<TViewModel, TViewModelProp?>> viewModelProperty,
@@ -120,6 +130,10 @@ public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(
120130
/// It should be noted that the observable should provide an initial value, otherwise that can result
121131
/// in an inconsistent performance.
122132
/// </remarks>
133+
#if NET6_0_OR_GREATER
134+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
135+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
136+
#endif
123137
public static ValidationHelper ValidationRule<TViewModel>(
124138
this TViewModel viewModel,
125139
IObservable<bool> validationObservable,
@@ -164,6 +178,10 @@ public static ValidationHelper ValidationRule<TViewModel>(
164178
/// It should be noted that the observable should provide an initial value, otherwise that can result
165179
/// in an inconsistent performance.
166180
/// </remarks>
181+
#if NET6_0_OR_GREATER
182+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
183+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
184+
#endif
167185
public static ValidationHelper ValidationRule<TViewModel, TValue>(
168186
this TViewModel viewModel,
169187
IObservable<TValue> validationObservable,
@@ -207,6 +225,10 @@ public static ValidationHelper ValidationRule<TViewModel, TValue>(
207225
/// It should be noted that the observable should provide an initial value, otherwise that can result
208226
/// in an inconsistent performance.
209227
/// </remarks>
228+
#if NET6_0_OR_GREATER
229+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
230+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
231+
#endif
210232
public static ValidationHelper ValidationRule<TViewModel>(
211233
this TViewModel viewModel,
212234
IObservable<IValidationState> validationObservable)
@@ -239,6 +261,10 @@ public static ValidationHelper ValidationRule<TViewModel>(
239261
/// It should be noted that the observable should provide an initial value, otherwise that can result
240262
/// in an inconsistent performance.
241263
/// </remarks>
264+
#if NET6_0_OR_GREATER
265+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
266+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
267+
#endif
242268
public static ValidationHelper ValidationRule<TViewModel, TValue>(
243269
this TViewModel viewModel,
244270
IObservable<TValue> validationObservable)
@@ -275,6 +301,10 @@ public static ValidationHelper ValidationRule<TViewModel, TValue>(
275301
/// It should be noted that the observable should provide an initial value, otherwise that can result
276302
/// in an inconsistent performance.
277303
/// </remarks>
304+
#if NET6_0_OR_GREATER
305+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
306+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
307+
#endif
278308
public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(
279309
this TViewModel viewModel,
280310
Expression<Func<TViewModel, TViewModelProp>> viewModelProperty,
@@ -328,6 +358,10 @@ public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(
328358
/// It should be noted that the observable should provide an initial value, otherwise that can result
329359
/// in an inconsistent performance.
330360
/// </remarks>
361+
#if NET6_0_OR_GREATER
362+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
363+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
364+
#endif
331365
public static ValidationHelper ValidationRule<TViewModel, TViewModelProp, TValue>(
332366
this TViewModel viewModel,
333367
Expression<Func<TViewModel, TViewModelProp>> viewModelProperty,
@@ -379,6 +413,10 @@ public static ValidationHelper ValidationRule<TViewModel, TViewModelProp, TValue
379413
/// It should be noted that the observable should provide an initial value, otherwise that can result
380414
/// in an inconsistent performance.
381415
/// </remarks>
416+
#if NET6_0_OR_GREATER
417+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
418+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
419+
#endif
382420
public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(
383421
this TViewModel viewModel,
384422
Expression<Func<TViewModel, TViewModelProp>> viewModelProperty,
@@ -419,6 +457,10 @@ public static ValidationHelper ValidationRule<TViewModel, TViewModelProp>(
419457
/// It should be noted that the observable should provide an initial value, otherwise that can result
420458
/// in an inconsistent performance.
421459
/// </remarks>
460+
#if NET6_0_OR_GREATER
461+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
462+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
463+
#endif
422464
public static ValidationHelper ValidationRule<TViewModel, TViewModelProp, TValue>(
423465
this TViewModel viewModel,
424466
Expression<Func<TViewModel, TViewModelProp>> viewModelProperty,
@@ -525,6 +567,10 @@ public static IObservable<bool> IsValid<TViewModel>(this TViewModel viewModel)
525567
/// <param name="validation">The disposable validation component to register into the context.</param>
526568
/// <typeparam name="TValidationComponent">The disposable validation component type.</typeparam>
527569
/// <returns>The bindable validation helper holding the disposable.</returns>
570+
#if NET6_0_OR_GREATER
571+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
572+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
573+
#endif
528574
private static ValidationHelper RegisterValidation<TValidationComponent>(
529575
this IValidatableViewModel viewModel,
530576
TValidationComponent validation)

src/ReactiveUI.Validation/Extensions/ViewForExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public static class ViewForExtensions
3737
/// IValidationTextFormatter&lt;string&gt; into Splat.Locator.
3838
/// </param>
3939
/// <returns>Returns a <see cref="IDisposable"/> object.</returns>
40+
#if NET6_0_OR_GREATER
41+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
42+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
43+
#endif
4044
public static IDisposable BindValidation<TView, TViewModel, TViewModelProperty, TViewProperty>(
4145
this TView view,
4246
TViewModel? viewModel,
@@ -74,6 +78,10 @@ public static IDisposable BindValidation<TView, TViewModel, TViewModelProperty,
7478
/// IValidationTextFormatter&lt;string&gt; into Splat.Locator.
7579
/// </param>
7680
/// <returns>Returns a <see cref="IDisposable"/> object.</returns>
81+
#if NET6_0_OR_GREATER
82+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
83+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
84+
#endif
7785
public static IDisposable BindValidation<TView, TViewModel, TViewProperty>(
7886
this TView view,
7987
TViewModel? viewModel,
@@ -106,6 +114,10 @@ public static IDisposable BindValidation<TView, TViewModel, TViewProperty>(
106114
/// IValidationTextFormatter&lt;string&gt; into Splat.Locator.
107115
/// </param>
108116
/// <returns>Returns a <see cref="IDisposable"/> object.</returns>
117+
#if NET6_0_OR_GREATER
118+
[RequiresDynamicCode("WhenAnyValue uses expression trees which require dynamic code generation in AOT scenarios.")]
119+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
120+
#endif
109121
public static IDisposable BindValidation<TView, TViewModel, TViewProperty>(
110122
this TView view,
111123
TViewModel? viewModel,

src/ReactiveUI.Validation/Helpers/ReactiveValidationObject.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
using System.Collections;
88
using System.Collections.Generic;
99
using System.ComponentModel;
10+
using System.Diagnostics.CodeAnalysis;
1011
using System.Linq;
1112
using System.Reactive.Concurrency;
1213
using System.Reactive.Disposables;
1314
using System.Reactive.Disposables.Fluent;
1415
using System.Reactive.Linq;
16+
1517
using DynamicData;
18+
1619
using ReactiveUI.Validation.Abstractions;
1720
using ReactiveUI.Validation.Collections;
1821
using ReactiveUI.Validation.Components.Abstractions;
1922
using ReactiveUI.Validation.Contexts;
2023
using ReactiveUI.Validation.Formatters;
2124
using ReactiveUI.Validation.Formatters.Abstractions;
25+
2226
using Splat;
2327

2428
namespace ReactiveUI.Validation.Helpers;
@@ -44,6 +48,9 @@ public abstract class ReactiveValidationObject : ReactiveObject, IValidatableVie
4448
/// default value, implement <see cref="IValidationTextFormatter{TOut}"/> and register an instance of
4549
/// IValidationTextFormatter&lt;string&gt; into Splat.Locator.
4650
/// </param>
51+
#if NET6_0_OR_GREATER
52+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
53+
#endif
4754
protected ReactiveValidationObject(
4855
IScheduler? scheduler = null,
4956
IValidationTextFormatter<string>? formatter = null)

src/ReactiveUI.Validation/Helpers/ValidationHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// See the LICENSE file in the project root for full license information.
55

66
using System;
7+
using System.Diagnostics.CodeAnalysis;
78
using System.Reactive.Linq;
9+
810
using ReactiveUI.Validation.Collections;
911
using ReactiveUI.Validation.Components.Abstractions;
1012
using ReactiveUI.Validation.States;
@@ -28,6 +30,9 @@ public class ValidationHelper : ReactiveObject, IDisposable
2830
/// </summary>
2931
/// <param name="validation">Validation property.</param>
3032
/// <param name="cleanup">The disposable to dispose when the helper is disposed.</param>
33+
#if NET6_0_OR_GREATER
34+
[RequiresUnreferencedCode("WhenAnyValue may reference members that could be trimmed in AOT scenarios.")]
35+
#endif
3136
public ValidationHelper(IValidationComponent validation, IDisposable? cleanup = null)
3237
{
3338
_validation = validation ?? throw new ArgumentNullException(nameof(validation));

0 commit comments

Comments
 (0)