Skip to content

Commit

Permalink
Add MethodToCommandConverter nullable annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
workgroupengineering committed Jan 23, 2021
1 parent 5cc5b30 commit dadc2ed
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs
@@ -1,12 +1,13 @@
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Windows.Input;
using Avalonia.Utilities;

#nullable enable
namespace Avalonia.Data.Converters
{
class MethodToCommandConverter : ICommand
Expand All @@ -18,11 +19,11 @@ class MethodToCommandConverter : ICommand
.GetProperty(nameof(CultureInfo.CurrentCulture), BindingFlags.Public | BindingFlags.Static);
readonly Func<object, bool> canExecute;
readonly Action<object> execute;
readonly WeakPropertyChangedProxy weakPropertyChanged;
readonly PropertyChangedEventHandler propertyChangedEventHandler;
readonly string[] dependencyProperties;
readonly WeakPropertyChangedProxy? weakPropertyChanged;
readonly PropertyChangedEventHandler? propertyChangedEventHandler;
readonly string[]? dependencyProperties;

public MethodToCommandConverter(Delegate action)
public MethodToCommandConverter([DisallowNull] Delegate action)
{
var target = action.Target;
var canExecuteMethodName = "Can" + action.Method.Name;
Expand Down Expand Up @@ -74,7 +75,7 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
}

#pragma warning disable 0067
public event EventHandler CanExecuteChanged;
public event EventHandler? CanExecuteChanged;
#pragma warning restore 0067

public bool CanExecute(object parameter) => canExecute(parameter);
Expand Down Expand Up @@ -140,7 +141,7 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
);

}
Action<object> action = null;
Action<object> action;
try
{
action = Expression
Expand Down Expand Up @@ -173,6 +174,7 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
private static Expression? ConvertTarget(object? target, MethodInfo method) =>
target is null ? null : Expression.Convert(Expression.Constant(target), method.DeclaringType);

#nullable disable
internal class WeakPropertyChangedProxy
{
readonly WeakReference<PropertyChangedEventHandler> _listener = new WeakReference<PropertyChangedEventHandler>(null);
Expand Down Expand Up @@ -215,5 +217,6 @@ void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
}

}
#nullable restore
}
}

0 comments on commit dadc2ed

Please sign in to comment.