Skip to content

Commit

Permalink
feat: remove warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitism committed Jul 30, 2024
1 parent 00497f6 commit d7be559
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 49 deletions.
3 changes: 0 additions & 3 deletions sample/Sample/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Linq;
using Avalonia.Controls;
using Avalonia.Media;
using Irihi.Avalonia.Shared.Helpers;

namespace Sample;

Expand Down
4 changes: 2 additions & 2 deletions src/Irihi.Avalonia.Shared.Public/Common/IRIHI_CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public IRIHI_CommandBase(Action execute, Func<bool> canExecute)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool CanExecute(object parameter)
public bool CanExecute(object? parameter)
{
return _canExecute is null || _canExecute.Invoke();
}

public void Execute(object parameter)
public void Execute(object? parameter)
{
_execute.Invoke();
}
Expand Down
12 changes: 6 additions & 6 deletions src/Irihi.Avalonia.Shared.Public/Common/IRIHI_CommandBase`T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public bool CanExecute(T? parameter)
return _canExecute is null || _canExecute.Invoke(parameter);
}

public bool CanExecute(object parameter)
public bool CanExecute(object? parameter)
{
if (!TryGetCommandArgument(parameter, out var result))
{
Expand All @@ -45,7 +45,7 @@ public void Execute(T? parameter)
_execute(parameter);
}

public void Execute(object parameter)
public void Execute(object? parameter)
{
if (!TryGetCommandArgument(parameter, out var result))
{
Expand All @@ -59,23 +59,23 @@ internal static bool TryGetCommandArgument(object? parameter, out T? result)
{
if (parameter is null && default(T) is null)
{
result = default(T);
result = default;
return true;
}
if (parameter is T obj)
{
result = obj;
return true;
}
result = default (T);
result = default;
return false;
}

public void NotifyCanExecuteChanged()
{
EventHandler canExecuteChanged = this.CanExecuteChanged;
EventHandler? canExecuteChanged = this.CanExecuteChanged;
if (canExecuteChanged is null)
return;
canExecuteChanged((object) this, EventArgs.Empty);
canExecuteChanged(this, EventArgs.Empty);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Irihi.Avalonia.Shared.Common;
Expand All @@ -17,7 +16,7 @@ public class IRIHI_ObservableBase: INotifyPropertyChanged, INotifyPropertyChangi

protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChanged ?.Invoke((object) this, e);
PropertyChanged ?.Invoke(this, e);
}

protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
Expand Down
3 changes: 0 additions & 3 deletions src/Irihi.Avalonia.Shared.Public/Helpers/MathHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using Avalonia.Controls.Platform;
using Avalonia.Utilities;

namespace Irihi.Avalonia.Shared.Helpers;

public static class MathHelpers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Reactive;
using Avalonia.Reactive;

namespace Irihi.Avalonia.Shared.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using Xunit;

namespace Irihi.Avalonia.Shared.Common.Tests;

public class IRIHI_CommandBaseGenericTests
Expand Down Expand Up @@ -57,7 +54,7 @@ public void NotifyCanExecuteChangedRaisesEvent()
{
var command = new IRIHI_CommandBase<object>(_ => { });
bool eventRaised = false;
command.CanExecuteChanged += (sender, e) => eventRaised = true;
command.CanExecuteChanged += (_, _) => eventRaised = true;

command.NotifyCanExecuteChanged();

Expand Down Expand Up @@ -87,7 +84,7 @@ public void UnsubscribingFromCanExecuteChangedEventWorks()
var command = new IRIHI_CommandBase<object>(_ => { });
bool eventRaised = false;

EventHandler handler = (sender, e) => eventRaised = true;
EventHandler handler = (_, _) => eventRaised = true;
command.CanExecuteChanged += handler;
command.CanExecuteChanged -= handler;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using Xunit;

namespace Irihi.Avalonia.Shared.Common.Tests;

public class IRIHI_CommandBaseTests
Expand Down Expand Up @@ -41,7 +38,7 @@ public void NotifyCanExecuteChangedRaisesEvent()
{
var command = new IRIHI_CommandBase(() => { });
bool eventRaised = false;
command.CanExecuteChanged += (sender, e) => eventRaised = true;
command.CanExecuteChanged += (_, _) => eventRaised = true;

command.NotifyCanExecuteChanged();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Xunit;

namespace Irihi.Avalonia.Shared.Common.Tests;

Expand Down Expand Up @@ -32,7 +30,7 @@ public void PropertyChangedEventFiresOnPropertyChange()
{
var testObject = new TestObservable();
bool eventFired = false;
testObject.PropertyChanged += (sender, e) =>
testObject.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(TestObservable.TestProperty))
eventFired = true;
Expand All @@ -49,7 +47,7 @@ public void PropertyChangedEventDoesNotFireWhenValueIsUnchanged()
var testObject = new TestObservable();
testObject.TestProperty = "Initial Value";
bool eventFired = false;
testObject.PropertyChanged += (sender, e) => eventFired = true;
testObject.PropertyChanged += (_, _) => eventFired = true;

testObject.TestProperty = "Initial Value";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls;
using Avalonia.Media;
using Irihi.Avalonia.Shared.Helpers;
using Irihi.Avalonia.Shared.Reactive;

namespace Irihi.Avalonia.Shared.UnitTest.Helpers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public void CalculateDistanceFromLogicalParent_Default()
var parent = new StackPanel();
var child = new Button();
parent.Children.Add(child);
Assert.Equal(1, child.CalculateDistanceFromLogicalParent<StackPanel>(-1));
Assert.Equal(-1, child.CalculateDistanceFromLogicalParent<Grid>(-1));
Assert.Equal(1, child.CalculateDistanceFromLogicalParent<StackPanel>());
Assert.Equal(-1, child.CalculateDistanceFromLogicalParent<Grid>());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Subscribe_Action_Success()
bool called = false;
var textBlock = new TextBlock();
IObservable<string?> observable = textBlock.GetObservable(TextBlock.TextProperty);
IDisposable disposable = observable.Subscribe(i => called = true);
IDisposable disposable = observable.Subscribe(_ => called = true);
textBlock.Text = "Hello, World!";
disposable.Dispose();
Assert.True(called);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Irihi.Avalonia.Shared.Helpers;
Expand All @@ -18,7 +17,7 @@ void Handler(object? sender, RoutedEventArgs args)
count++;
}
Button.ClickEvent.AddHandler(Handler, button);
button.RaiseEvent(new RoutedEventArgs(){ Source = button, RoutedEvent = Button.ClickEvent});
button.RaiseEvent(new RoutedEventArgs { Source = button, RoutedEvent = Button.ClickEvent});
Assert.Equal(1, count);
}

Expand Down Expand Up @@ -146,7 +145,6 @@ void Handler(object? sender, RoutedEventArgs args)
}
var result = Button.ClickEvent.AddDisposableHandler(Handler, button, button2, button3);
result.Dispose();
;
button.RaiseEvent(new RoutedEventArgs(){ Source = button, RoutedEvent = Button.ClickEvent});
button2.RaiseEvent(new RoutedEventArgs(){ Source = button2, RoutedEvent = Button.ClickEvent});
button3.RaiseEvent(new RoutedEventArgs(){ Source = button3, RoutedEvent = Button.ClickEvent});
Expand Down Expand Up @@ -304,7 +302,7 @@ void Handler(object? sender, RoutedEventArgs args)
{
count++;
}
var disposables = Button.ClickEvent.AddDisposableHandler(Handler, new Button[]{button, button2, button3}, RoutingStrategies.Bubble, true);
var disposables = Button.ClickEvent.AddDisposableHandler(Handler, new[]{button, button2, button3}, RoutingStrategies.Bubble, true);
button.RaiseEvent(new RoutedEventArgs(){ Source = button, RoutedEvent = Button.ClickEvent});
button2.RaiseEvent(new RoutedEventArgs(){ Source = button2, RoutedEvent = Button.ClickEvent});
button3.RaiseEvent(new RoutedEventArgs(){ Source = button3, RoutedEvent = Button.ClickEvent});
Expand Down Expand Up @@ -410,14 +408,13 @@ void Handler(object? sender, GotFocusEventArgs args)
public void EventHandler_AddHandler_Multi_Type_List_Success()
{
var button = new Button();
var panel = new Panel();
var button2 = new Button();
int count = 0;
void Handler(object? sender, RoutedEventArgs args)
{
count++;
}
Button.ClickEvent.AddDisposableHandler<RoutedEventArgs, Button>(Handler, RoutingStrategies.Bubble, false, button, button2);
Button.ClickEvent.AddDisposableHandler(Handler, RoutingStrategies.Bubble, false, button, button2);
button.RaiseEvent(new RoutedEventArgs(){ Source = button, RoutedEvent = Button.ClickEvent});

Assert.Equal(1, count);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System.ComponentModel;
using System.Net.Http.Headers;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
using Irihi.Avalonia.Shared.Shapes;

namespace Irihi.Avalonia.Shared.UnitTest.Shapes;
Expand Down

0 comments on commit d7be559

Please sign in to comment.