Skip to content

Commit

Permalink
null checks in new code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm committed Nov 25, 2024
1 parent b701be0 commit d30f691
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/Consolonia.Core/Controls/FileSavePicker.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ private void OnDoubleTapped(object sender, TappedEventArgs e)

private async void OnOK(object sender, RoutedEventArgs e)
{
var lifetime = (IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime;
var lifetime = Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime;

Check warning on line 61 in src/Consolonia.Core/Controls/FileSavePicker.axaml.cs

View workflow job for this annotation

GitHub Actions / build

"[PossibleNullReferenceException] Possible 'System.NullReferenceException'" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Controls/FileSavePicker.axaml.cs(61,28)
ArgumentNullException.ThrowIfNull(lifetime);
ArgumentNullException.ThrowIfNull(lifetime.MainWindow);

var savePath = ViewModel.SavePath;
if (!Path.IsPathFullyQualified(ViewModel.SavePath))
Expand Down
19 changes: 3 additions & 16 deletions src/Consolonia.Core/Controls/FileSavePickerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Consolonia.Core.Controls
{
public partial class FileSavePickerViewModel : PickerViewModelBase<FilePickerSaveOptions>
{
[ObservableProperty] private string _savePath;
[ObservableProperty] private string _savePath=string.Empty;

[ObservableProperty] [NotifyPropertyChangedFor(nameof(SelectedFile))]
private IStorageItem _selectedItem;
Expand All @@ -15,34 +15,21 @@ public FileSavePickerViewModel(FilePickerSaveOptions options)
: base(options)
{
ArgumentNullException.ThrowIfNull(options, nameof(options));
this.PropertyChanged += FileSavePickerViewModel_PropertyChanged; ;
this.PropertyChanged += FileSavePickerViewModel_PropertyChanged;

Check notice on line 18 in src/Consolonia.Core/Controls/FileSavePickerViewModel.cs

View workflow job for this annotation

GitHub Actions / build

"[ArrangeThisQualifier] Qualifier 'this.' is redundant" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Controls/FileSavePickerViewModel.cs(18,13)
}

private void FileSavePickerViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(SelectedFile))
{
SavePath = SelectedFile?.Path.LocalPath;
SavePath = SelectedFile.Path.LocalPath;
}
}

public IStorageFile SelectedFile => SelectedItem as IStorageFile;

protected override bool FilterItem(IStorageItem item)
{
//if (item is IStorageFolder) return true;
//if (item is IStorageFile file)
//{
// // ReSharper disable ConstantConditionalAccessQualifier
// if (SelectedFileType == null)
// return true;

// foreach (string pattern in SelectedFileType.Patterns)
// if (file.Path.LocalPath.EndsWith(pattern.TrimStart('*'), StringComparison.OrdinalIgnoreCase))
// return true;
// return false;
//}

return true;
}
}
Expand Down

0 comments on commit d30f691

Please sign in to comment.