Skip to content

Commit

Permalink
null warnings fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
DocBrown101 committed May 20, 2024
1 parent 3fd5216 commit 0cb5518
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 54 deletions.
8 changes: 4 additions & 4 deletions build-all.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ dotnet publish "$PSScriptRoot\src\$Project\$Project.csproj" `
--nologo

# Archiv Build
Compress-Archive -Path "$BuildPathLinuxX64\$Project" -DestinationPath $ArchiveLinuxX64
Compress-Archive -Path "$BuildPathLinuxARM64\$Project" -DestinationPath $ArchiveLinuxARM64
Compress-Archive -Path "$BuildPathWindowsX64\$Project.exe" -DestinationPath $ArchiveWindowsX64
Compress-Archive -Path "$BuildPathWindowsARM64\$Project.exe" -DestinationPath $ArchiveWindowsARM64
Compress-Archive -Path "$BuildPathLinuxX64\File-Content-Search" -DestinationPath $ArchiveLinuxX64
Compress-Archive -Path "$BuildPathLinuxARM64\File-Content-Search" -DestinationPath $ArchiveLinuxARM64
Compress-Archive -Path "$BuildPathWindowsX64\File-Content-Search.exe" -DestinationPath $ArchiveWindowsX64
Compress-Archive -Path "$BuildPathWindowsARM64\File-Content-Search.exe" -DestinationPath $ArchiveWindowsARM64
4 changes: 2 additions & 2 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ csharp_style_throw_expression = true:warning
csharp_style_conditional_delegate_call = true:warning
# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
# Expression-level preferences
csharp_prefer_braces = true:suggestion
csharp_prefer_braces = when_multiline
csharp_style_deconstructed_variable_declaration = true:warning
csharp_prefer_simple_default_expression = true:warning
csharp_style_pattern_local_over_anonymous_function = true:warning
csharp_style_inlined_variable_declaration = true:warning
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_prefer_primary_constructors = false:silent
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
Expand Down
6 changes: 3 additions & 3 deletions src/ContentSearch/AppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class AppState : IDisposable
{
private CancellationTokenSource cancellationTokenSource;
private CancellationTokenSource? cancellationTokenSource;
private State currentState;
private bool isDisposed;

Expand All @@ -14,7 +14,7 @@ public AppState()
this.CurrentState = State.Idle;
}

public event EventHandler<State> CurrentStateChanged;
public event EventHandler<State>? CurrentStateChanged;

public enum State
{
Expand Down Expand Up @@ -71,7 +71,7 @@ protected virtual void Dispose(bool disposing)

if (disposing)
{
this.cancellationTokenSource.Dispose();
this.cancellationTokenSource?.Dispose();
}

this.isDisposed = true;
Expand Down
1 change: 1 addition & 0 deletions src/ContentSearch/ContentSearch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ApplicationIcon>Assets/App.ico</ApplicationIcon>
<AssemblyName>File-Content-Search</AssemblyName>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
Expand Down
4 changes: 0 additions & 4 deletions src/ContentSearch/Settings/GeneralSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
public class GeneralSettings
{
public int Property1 { get; set; }

public string Property2 { get; set; }

public bool Property4 { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/ContentSearch/ViewModels/AppStateViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AppStateViewModel : ViewModelBase
private SolidColorBrush commandTextColor = new SolidColorBrush(Colors.Green);

private int searchProgressValue;
private string fileCountStatus;
private string fileCountStatus = string.Empty;
private bool isBusy;
private double progress;

Expand Down Expand Up @@ -64,7 +64,7 @@ public void IncrementProgress(int fileCount)
this.Progress = (double)this.searchProgressValue++ / fileCount;
}

private void ApplicationStateOnCurrentStateChanged(object sender, AppState.State state)
private void ApplicationStateOnCurrentStateChanged(object? sender, AppState.State state)
{
switch (state)
{
Expand Down
13 changes: 8 additions & 5 deletions src/ContentSearch/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ private async Task OpenFolderPicker()

private void OpenCurrentDirectory()
{
var directoryInfo = new DirectoryInfo(this.SearchSettings.SearchPath);

if (directoryInfo.Exists)
if (this.SearchSettings.SearchPath != null)
{
Process.Start("explorer", directoryInfo.FullName);
var directoryInfo = new DirectoryInfo(this.SearchSettings.SearchPath);

if (directoryInfo.Exists)
{
Process.Start("explorer", directoryInfo.FullName);
}
}
}

Expand Down Expand Up @@ -254,7 +257,7 @@ private HashSet<string> GetExcludedSubdirectoryNames()
return excludedSubdirectoryNames;
}

private void AddFileContentSearchResults(FileContentSearchResult searchTextResult, int fileCount)
private void AddFileContentSearchResults(FileContentSearchResult? searchTextResult, int fileCount)
{
if (searchTextResult != null)
{
Expand Down
24 changes: 12 additions & 12 deletions src/ContentSearch/ViewModels/RelayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class RelayCommand : ICommand
{
private readonly Action execute;

private readonly Func<bool> canExecute;
private readonly Func<bool>? canExecute;

public event EventHandler? CanExecuteChanged;

Expand All @@ -16,41 +16,41 @@ public RelayCommand(Action execute)
{
}

public RelayCommand(Action execute, Func<bool> canExecute)
public RelayCommand(Action execute, Func<bool>? canExecute)
{
this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
this.canExecute = canExecute;
}

public bool CanExecute(object parameter) => this.canExecute == null || this.canExecute();
public bool CanExecute(object? parameter) => this.canExecute == null || this.canExecute();

public void Execute(object parameter) => this.execute();
public void Execute(object? parameter) => this.execute();

public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}

public class RelayCommand<T> : ICommand
{
private readonly Action<T> execute;
private readonly Action<T?> execute;

private readonly Func<T, bool> canExecute;
private readonly Func<T?, bool>? canExecute;

public event EventHandler CanExecuteChanged;
public event EventHandler? CanExecuteChanged;

public RelayCommand(Action<T> execute)
public RelayCommand(Action<T?> execute)
: this(execute, null)
{
{
}

public RelayCommand(Action<T> execute, Func<T, bool> canExecute)
public RelayCommand(Action<T?> execute, Func<T?, bool>? canExecute)
{
this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
this.canExecute = canExecute;
}

public bool CanExecute(object parameter) => this.canExecute == null || this.canExecute((T)parameter);
public bool CanExecute(object? parameter) => this.canExecute == null || this.canExecute(parameter is null ? default : (T)parameter);

public void Execute(object parameter) => this.execute((T)parameter);
public void Execute(object? parameter) => this.execute(parameter is null ? default : (T)parameter);

public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
Expand Down
12 changes: 6 additions & 6 deletions src/ContentSearch/ViewModels/SearchParameterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SearchParameterViewModel : ViewModelBase
{
private readonly SearchSettings searchSettings;

public string SearchPath
public string? SearchPath
{
get => this.searchSettings.SearchPath;
set
Expand All @@ -19,7 +19,7 @@ public string SearchPath
}
}

public string SearchText1
public string? SearchText1
{
get => this.searchSettings.SearchText1;
set
Expand All @@ -31,7 +31,7 @@ public string SearchText1
}
}

public string SearchText2
public string? SearchText2
{
get => this.searchSettings.SearchText2;
set
Expand All @@ -43,7 +43,7 @@ public string SearchText2
}
}

public string FileExtensions
public string? FileExtensions
{
get => this.searchSettings.FileExtensions;
set
Expand All @@ -55,7 +55,7 @@ public string FileExtensions
}
}

public string ExcludedSubdirectoryName1
public string? ExcludedSubdirectoryName1
{
get => this.searchSettings.ExcludedSubdirectoryName1;
set
Expand All @@ -67,7 +67,7 @@ public string ExcludedSubdirectoryName1
}
}

public string ExcludedSubdirectoryName2
public string? ExcludedSubdirectoryName2
{
get => this.searchSettings.ExcludedSubdirectoryName2;
set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Convert an integer percentage (0 to 100) to a double between (0.0d and 1.0d)
public class IntPercentageToDoubleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
var res = 0.0d;
if (value is int intVal)
Expand All @@ -27,7 +27,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
return res;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ContentSearch/Views/Converter/InverseBooleanConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

public class InverseBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return !(bool)value;
return value is bool inputValue ? !inputValue : true;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return !(bool)value;
return value is bool inputValue ? !inputValue : true;
}
}
}
4 changes: 2 additions & 2 deletions src/ContentSearch/Views/Converter/ToggleButtonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ToggleButtonConverter : IValueConverter
public required string TrueValue { get; set; }
public required string FalseValue { get; set; }

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool isChecked && isChecked)
{
Expand All @@ -18,7 +18,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
return this.FalseValue;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Services/FileContentSearchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class FileContentSearchOptions

public FileContentSearchOptions(ILocalizationService localizationService,
IMessageBoxService messageBoxService,
string searchPath,
string? searchPath,
ICollection<string> searchTags,
bool checkUpperLowerCase,
bool checkAllFiles,
string fileExtensions,
string? fileExtensions,
bool excludSubdirectoryNames,
ICollection<string> excludedSubdirectoryNames)
{
this.SearchPath = searchPath.Trim();
this.SearchPath = searchPath == null ? string.Empty : searchPath.Trim();
this.SearchTags = searchTags;
this.localizationService = localizationService;
this.messageBoxService = messageBoxService;
Expand Down
2 changes: 1 addition & 1 deletion src/Services/FileContentSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void SearchText(string searchFile, int fileCount, FileContentSearchOptio

using (var streamReader = new StreamReader(fileInfo.FullName, encoding))
{
string line;
string? line;
while ((line = streamReader.ReadLine()) != null && !cancellationToken.IsCancellationRequested)
{
foreach (var searchTag in searchTags)
Expand Down
7 changes: 6 additions & 1 deletion src/Services/FileSearchCacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@

public class FileSearchCacheService
{
private FileContentSearchOptions cachedOptions;
private FileContentSearchOptions? cachedOptions;

public ReadOnlyCollection<string> Files { get; private set; }

public FileSearchCacheService()
{
this.Files = new ReadOnlyCollection<string>([]);
}

public void SetCache(List<string> filesCorrespondingToTheOptions, FileContentSearchOptions options)
{
this.Files = new ReadOnlyCollection<string>(filesCorrespondingToTheOptions);
Expand Down
2 changes: 1 addition & 1 deletion src/Services/FileSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<List<string>> LoadFilesForSearch(FileContentSearchOptions opti
},
token).ConfigureAwait(false);

if (token.IsCancellationRequested) { return null; }
if (token.IsCancellationRequested) { return []; }

this.NotifyFileCountChangedAction(files.Count);

Expand Down
4 changes: 2 additions & 2 deletions src/Services/FileTypeBasedTextExtraction/DocxToTextService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private string GetTextFromDocX(string filePath)

var xmlNamespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
xmlNamespaceManager.AddNamespace("w", WordprocessingMlNamespace);
var xmlNode = xmlDocument.DocumentElement.SelectSingleNode(BodyXPath, xmlNamespaceManager);
var xmlNode = xmlDocument.DocumentElement?.SelectSingleNode(BodyXPath, xmlNamespaceManager);

stringBuilder.Append(this.ReadTextFromNodeRecursive(xmlNode));
}
Expand All @@ -57,7 +57,7 @@ private string GetTextFromDocX(string filePath)
return stringBuilder.ToString();
}

private string ReadTextFromNodeRecursive(XmlNode xmlNode)
private string ReadTextFromNodeRecursive(XmlNode? xmlNode)
{
if (xmlNode == null || xmlNode.NodeType != XmlNodeType.Element)
{
Expand Down
1 change: 1 addition & 0 deletions src/Services/Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
Expand Down

0 comments on commit 0cb5518

Please sign in to comment.