Skip to content

Commit cd7a981

Browse files
committed
Switched property name args to string?
1 parent 4238e6e commit cd7a981

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

Microsoft.Toolkit.Mvvm/ComponentModel/ObservableObject.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public abstract class ObservableObject : INotifyPropertyChanged, INotifyProperty
3434
/// </summary>
3535
/// <param name="propertyName">(optional) The name of the property that changed.</param>
3636
/// <remarks>The base implementation only raises the <see cref="PropertyChanged"/> event.</remarks>
37-
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null!)
37+
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
3838
{
3939
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
4040
}
@@ -45,7 +45,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
4545
/// </summary>
4646
/// <param name="propertyName">(optional) The name of the property that changed.</param>
4747
/// <remarks>The base implementation only raises the <see cref="PropertyChanging"/> event.</remarks>
48-
protected virtual void OnPropertyChanging([CallerMemberName] string propertyName = null!)
48+
protected virtual void OnPropertyChanging([CallerMemberName] string? propertyName = null)
4949
{
5050
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));
5151
}
@@ -64,7 +64,7 @@ protected virtual void OnPropertyChanging([CallerMemberName] string propertyName
6464
/// The <see cref="PropertyChanging"/> and <see cref="PropertyChanged"/> events are not raised
6565
/// if the current and new value for the target property are the same.
6666
/// </remarks>
67-
protected bool SetProperty<T>(ref T field, T newValue, [CallerMemberName] string propertyName = null!)
67+
protected bool SetProperty<T>(ref T field, T newValue, [CallerMemberName] string? propertyName = null)
6868
{
6969
return SetProperty(ref field, newValue, EqualityComparer<T>.Default, propertyName);
7070
}
@@ -81,7 +81,7 @@ protected bool SetProperty<T>(ref T field, T newValue, [CallerMemberName] string
8181
/// <param name="comparer">The <see cref="IEqualityComparer{T}"/> instance to use to compare the input values.</param>
8282
/// <param name="propertyName">(optional) The name of the property that changed.</param>
8383
/// <returns><see langword="true"/> if the property was changed, <see langword="false"/> otherwise.</returns>
84-
protected bool SetProperty<T>(ref T field, T newValue, IEqualityComparer<T> comparer, [CallerMemberName] string propertyName = null!)
84+
protected bool SetProperty<T>(ref T field, T newValue, IEqualityComparer<T> comparer, [CallerMemberName] string? propertyName = null)
8585
{
8686
if (comparer.Equals(field, newValue))
8787
{
@@ -115,7 +115,7 @@ protected bool SetProperty<T>(ref T field, T newValue, IEqualityComparer<T> comp
115115
/// The <see cref="PropertyChanging"/> and <see cref="PropertyChanged"/> events are not raised
116116
/// if the current and new value for the target property are the same.
117117
/// </remarks>
118-
protected bool SetProperty<T>(T oldValue, T newValue, Action<T> callback, [CallerMemberName] string propertyName = null!)
118+
protected bool SetProperty<T>(T oldValue, T newValue, Action<T> callback, [CallerMemberName] string? propertyName = null)
119119
{
120120
return SetProperty(oldValue, newValue, EqualityComparer<T>.Default, callback, propertyName);
121121
}
@@ -133,7 +133,7 @@ protected bool SetProperty<T>(T oldValue, T newValue, Action<T> callback, [Calle
133133
/// <param name="callback">A callback to invoke to update the property value.</param>
134134
/// <param name="propertyName">(optional) The name of the property that changed.</param>
135135
/// <returns><see langword="true"/> if the property was changed, <see langword="false"/> otherwise.</returns>
136-
protected bool SetProperty<T>(T oldValue, T newValue, IEqualityComparer<T> comparer, Action<T> callback, [CallerMemberName] string propertyName = null!)
136+
protected bool SetProperty<T>(T oldValue, T newValue, IEqualityComparer<T> comparer, Action<T> callback, [CallerMemberName] string? propertyName = null)
137137
{
138138
if (comparer.Equals(oldValue, newValue))
139139
{
@@ -201,7 +201,7 @@ protected bool SetProperty<T>(T oldValue, T newValue, IEqualityComparer<T> compa
201201
/// be used to access properties of a model that is directly stored as a property of the current instance.
202202
/// Additionally, this method can only be used if the wrapped item is a reference type.
203203
/// </remarks>
204-
protected bool SetProperty<T>(Expression<Func<T>> propertyExpression, T newValue, [CallerMemberName] string propertyName = null!)
204+
protected bool SetProperty<T>(Expression<Func<T>> propertyExpression, T newValue, [CallerMemberName] string? propertyName = null)
205205
{
206206
return SetProperty(propertyExpression, newValue, EqualityComparer<T>.Default, propertyName);
207207
}
@@ -219,7 +219,7 @@ protected bool SetProperty<T>(Expression<Func<T>> propertyExpression, T newValue
219219
/// <param name="comparer">The <see cref="IEqualityComparer{T}"/> instance to use to compare the input values.</param>
220220
/// <param name="propertyName">(optional) The name of the property that changed.</param>
221221
/// <returns><see langword="true"/> if the property was changed, <see langword="false"/> otherwise.</returns>
222-
protected bool SetProperty<T>(Expression<Func<T>> propertyExpression, T newValue, IEqualityComparer<T> comparer, [CallerMemberName] string propertyName = null!)
222+
protected bool SetProperty<T>(Expression<Func<T>> propertyExpression, T newValue, IEqualityComparer<T> comparer, [CallerMemberName] string? propertyName = null)
223223
{
224224
PropertyInfo? parentPropertyInfo;
225225
FieldInfo? parentFieldInfo = null;
@@ -292,7 +292,7 @@ parentExpression.Expression is ConstantExpression instanceExpression &&
292292
/// indicates that the new value being assigned to <paramref name="field"/> is different than the previous one,
293293
/// and it does not mean the new <typeparamref name="TTask"/> instance passed as argument is in any particular state.
294294
/// </remarks>
295-
protected bool SetPropertyAndNotifyOnCompletion<TTask>(ref TTask? field, Expression<Func<TTask?>> fieldExpression, TTask? newValue, [CallerMemberName] string propertyName = null!)
295+
protected bool SetPropertyAndNotifyOnCompletion<TTask>(ref TTask? field, Expression<Func<TTask?>> fieldExpression, TTask? newValue, [CallerMemberName] string? propertyName = null)
296296
where TTask : Task
297297
{
298298
// We invoke the overload with a callback here to avoid code duplication, and simply pass an empty callback.
@@ -324,7 +324,7 @@ protected bool SetPropertyAndNotifyOnCompletion<TTask>(ref TTask? field, Express
324324
/// The <see cref="PropertyChanging"/> and <see cref="PropertyChanged"/> events are not raised
325325
/// if the current and new value for the target property are the same.
326326
/// </remarks>
327-
protected bool SetPropertyAndNotifyOnCompletion<TTask>(ref TTask? field, Expression<Func<TTask?>> fieldExpression, TTask? newValue, Action<TTask?> callback, [CallerMemberName] string propertyName = null!)
327+
protected bool SetPropertyAndNotifyOnCompletion<TTask>(ref TTask? field, Expression<Func<TTask?>> fieldExpression, TTask? newValue, Action<TTask?> callback, [CallerMemberName] string? propertyName = null)
328328
where TTask : Task
329329
{
330330
if (ReferenceEquals(field, newValue))

Microsoft.Toolkit.Mvvm/ComponentModel/ObservableRecipient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected virtual void OnDeactivated()
114114
/// You should override this method if you wish to customize the channel being
115115
/// used to send the message (eg. if you need to use a specific token for the channel).
116116
/// </remarks>
117-
protected virtual void Broadcast<T>(T oldValue, T newValue, string propertyName)
117+
protected virtual void Broadcast<T>(T oldValue, T newValue, string? propertyName)
118118
{
119119
var message = new PropertyChangedMessage<T>(this, propertyName, oldValue, newValue);
120120

@@ -138,7 +138,7 @@ protected virtual void Broadcast<T>(T oldValue, T newValue, string propertyName)
138138
/// the <see cref="ObservableObject.PropertyChanging"/> and <see cref="ObservableObject.PropertyChanged"/> events
139139
/// are not raised if the current and new value for the target property are the same.
140140
/// </remarks>
141-
protected bool SetProperty<T>(ref T field, T newValue, bool broadcast, [CallerMemberName] string propertyName = null!)
141+
protected bool SetProperty<T>(ref T field, T newValue, bool broadcast, [CallerMemberName] string? propertyName = null)
142142
{
143143
return SetProperty(ref field, newValue, EqualityComparer<T>.Default, broadcast, propertyName);
144144
}
@@ -156,7 +156,7 @@ protected bool SetProperty<T>(ref T field, T newValue, bool broadcast, [CallerMe
156156
/// <param name="broadcast">If <see langword="true"/>, <see cref="Broadcast{T}"/> will also be invoked.</param>
157157
/// <param name="propertyName">(optional) The name of the property that changed.</param>
158158
/// <returns><see langword="true"/> if the property was changed, <see langword="false"/> otherwise.</returns>
159-
protected bool SetProperty<T>(ref T field, T newValue, IEqualityComparer<T> comparer, bool broadcast, [CallerMemberName] string propertyName = null!)
159+
protected bool SetProperty<T>(ref T field, T newValue, IEqualityComparer<T> comparer, bool broadcast, [CallerMemberName] string? propertyName = null)
160160
{
161161
if (!broadcast)
162162
{
@@ -195,7 +195,7 @@ protected bool SetProperty<T>(ref T field, T newValue, IEqualityComparer<T> comp
195195
/// the <see cref="ObservableObject.PropertyChanging"/> and <see cref="ObservableObject.PropertyChanged"/> events
196196
/// are not raised if the current and new value for the target property are the same.
197197
/// </remarks>
198-
protected bool SetProperty<T>(T oldValue, T newValue, Action<T> callback, bool broadcast, [CallerMemberName] string propertyName = null!)
198+
protected bool SetProperty<T>(T oldValue, T newValue, Action<T> callback, bool broadcast, [CallerMemberName] string? propertyName = null)
199199
{
200200
return SetProperty(oldValue, newValue, EqualityComparer<T>.Default, callback, broadcast, propertyName);
201201
}
@@ -214,7 +214,7 @@ protected bool SetProperty<T>(T oldValue, T newValue, Action<T> callback, bool b
214214
/// <param name="broadcast">If <see langword="true"/>, <see cref="Broadcast{T}"/> will also be invoked.</param>
215215
/// <param name="propertyName">(optional) The name of the property that changed.</param>
216216
/// <returns><see langword="true"/> if the property was changed, <see langword="false"/> otherwise.</returns>
217-
protected bool SetProperty<T>(T oldValue, T newValue, IEqualityComparer<T> comparer, Action<T> callback, bool broadcast, [CallerMemberName] string propertyName = null!)
217+
protected bool SetProperty<T>(T oldValue, T newValue, IEqualityComparer<T> comparer, Action<T> callback, bool broadcast, [CallerMemberName] string? propertyName = null)
218218
{
219219
if (!broadcast)
220220
{

Microsoft.Toolkit.Mvvm/Messaging/Messages/PropertyChangedMessage{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class PropertyChangedMessage<T>
2424
/// <param name="propertyName">The name of the property that changed.</param>
2525
/// <param name="oldValue">The value that the property had before the change.</param>
2626
/// <param name="newValue">The value that the property has after the change.</param>
27-
public PropertyChangedMessage(ObservableObject sender, string propertyName, T oldValue, T newValue)
27+
public PropertyChangedMessage(ObservableObject sender, string? propertyName, T oldValue, T newValue)
2828
{
2929
Sender = sender;
3030
PropertyName = propertyName;
@@ -40,7 +40,7 @@ public PropertyChangedMessage(ObservableObject sender, string propertyName, T ol
4040
/// <summary>
4141
/// Gets the name of the property that changed.
4242
/// </summary>
43-
public string PropertyName { get; }
43+
public string? PropertyName { get; }
4444

4545
/// <summary>
4646
/// Gets the value that the property had before the change.

0 commit comments

Comments
 (0)