18
18
using System ;
19
19
using System . Collections . Generic ;
20
20
using System . ComponentModel ;
21
+ using System . Diagnostics . CodeAnalysis ;
21
22
using System . Runtime . CompilerServices ;
22
23
using System . Threading . Tasks ;
23
24
@@ -84,7 +85,7 @@ protected void OnPropertyChanging([CallerMemberName] string? propertyName = null
84
85
/// The <see cref="PropertyChanging"/> and <see cref="PropertyChanged"/> events are not raised
85
86
/// if the current and new value for the target property are the same.
86
87
/// </remarks>
87
- protected bool SetProperty < T > ( ref T field , T newValue , [ CallerMemberName ] string ? propertyName = null )
88
+ protected bool SetProperty < T > ( [ NotNullIfNotNull ( "newValue" ) ] ref T field , T newValue , [ CallerMemberName ] string ? propertyName = null )
88
89
{
89
90
// We duplicate the code here instead of calling the overload because we can't
90
91
// guarantee that the invoked SetProperty<T> will be inlined, and we need the JIT
@@ -120,7 +121,7 @@ protected bool SetProperty<T>(ref T field, T newValue, [CallerMemberName] string
120
121
/// <param name="comparer">The <see cref="IEqualityComparer{T}"/> instance to use to compare the input values.</param>
121
122
/// <param name="propertyName">(optional) The name of the property that changed.</param>
122
123
/// <returns><see langword="true"/> if the property was changed, <see langword="false"/> otherwise.</returns>
123
- protected bool SetProperty < T > ( ref T field , T newValue , IEqualityComparer < T > comparer , [ CallerMemberName ] string ? propertyName = null )
124
+ protected bool SetProperty < T > ( [ NotNullIfNotNull ( "newValue" ) ] ref T field , T newValue , IEqualityComparer < T > comparer , [ CallerMemberName ] string ? propertyName = null )
124
125
{
125
126
if ( comparer . Equals ( field , newValue ) )
126
127
{
@@ -340,7 +341,7 @@ protected bool SetProperty<TModel, T>(T oldValue, T newValue, IEqualityComparer<
340
341
/// indicates that the new value being assigned to <paramref name="taskNotifier"/> is different than the previous one,
341
342
/// and it does not mean the new <see cref="Task"/> instance passed as argument is in any particular state.
342
343
/// </remarks>
343
- protected bool SetPropertyAndNotifyOnCompletion ( ref TaskNotifier ? taskNotifier , Task ? newValue , [ CallerMemberName ] string ? propertyName = null )
344
+ protected bool SetPropertyAndNotifyOnCompletion ( [ NotNull ] ref TaskNotifier ? taskNotifier , Task ? newValue , [ CallerMemberName ] string ? propertyName = null )
344
345
{
345
346
// We invoke the overload with a callback here to avoid code duplication, and simply pass an empty callback.
346
347
// The lambda expression here is transformed by the C# compiler into an empty closure class with a
@@ -368,7 +369,7 @@ protected bool SetPropertyAndNotifyOnCompletion(ref TaskNotifier? taskNotifier,
368
369
/// The <see cref="PropertyChanging"/> and <see cref="PropertyChanged"/> events are not raised
369
370
/// if the current and new value for the target property are the same.
370
371
/// </remarks>
371
- protected bool SetPropertyAndNotifyOnCompletion ( ref TaskNotifier ? taskNotifier , Task ? newValue , Action < Task ? > callback , [ CallerMemberName ] string ? propertyName = null )
372
+ protected bool SetPropertyAndNotifyOnCompletion ( [ NotNull ] ref TaskNotifier ? taskNotifier , Task ? newValue , Action < Task ? > callback , [ CallerMemberName ] string ? propertyName = null )
372
373
{
373
374
return SetPropertyAndNotifyOnCompletion ( taskNotifier ??= new ( ) , newValue , callback , propertyName ) ;
374
375
}
@@ -407,7 +408,7 @@ protected bool SetPropertyAndNotifyOnCompletion(ref TaskNotifier? taskNotifier,
407
408
/// indicates that the new value being assigned to <paramref name="taskNotifier"/> is different than the previous one,
408
409
/// and it does not mean the new <see cref="Task{TResult}"/> instance passed as argument is in any particular state.
409
410
/// </remarks>
410
- protected bool SetPropertyAndNotifyOnCompletion < T > ( ref TaskNotifier < T > ? taskNotifier , Task < T > ? newValue , [ CallerMemberName ] string ? propertyName = null )
411
+ protected bool SetPropertyAndNotifyOnCompletion < T > ( [ NotNull ] ref TaskNotifier < T > ? taskNotifier , Task < T > ? newValue , [ CallerMemberName ] string ? propertyName = null )
411
412
{
412
413
return SetPropertyAndNotifyOnCompletion ( taskNotifier ??= new ( ) , newValue , static _ => { } , propertyName ) ;
413
414
}
@@ -430,7 +431,7 @@ protected bool SetPropertyAndNotifyOnCompletion<T>(ref TaskNotifier<T>? taskNoti
430
431
/// The <see cref="PropertyChanging"/> and <see cref="PropertyChanged"/> events are not raised
431
432
/// if the current and new value for the target property are the same.
432
433
/// </remarks>
433
- protected bool SetPropertyAndNotifyOnCompletion < T > ( ref TaskNotifier < T > ? taskNotifier , Task < T > ? newValue , Action < Task < T > ? > callback , [ CallerMemberName ] string ? propertyName = null )
434
+ protected bool SetPropertyAndNotifyOnCompletion < T > ( [ NotNull ] ref TaskNotifier < T > ? taskNotifier , Task < T > ? newValue , Action < Task < T > ? > callback , [ CallerMemberName ] string ? propertyName = null )
434
435
{
435
436
return SetPropertyAndNotifyOnCompletion ( taskNotifier ??= new ( ) , newValue , callback , propertyName ) ;
436
437
}
0 commit comments