From e6fd8d4ab59fba8a3c3ed8f4b1c6f6300bbbfdea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Tue, 5 Sep 2023 21:22:30 +0200 Subject: [PATCH] Cleaning up warning --- .../ContainerSizeSizeScanProvider.cs | 24 ++---- .../ViewModels/ITabViewModel.cs | 4 +- .../Services/DialogServiceBase.cs | 8 +- .../Persistence/TabPersistenceService.cs | 8 +- .../RapidTravelModeKeyInputHandler.cs | 2 +- .../ViewModels/AppStateBase.cs | 10 +-- .../ViewModels/ItemViewModel.cs | 10 +-- .../ViewModels/TabViewModel.cs | 32 +++---- .../FrequencyNavigationViewModel.cs | 2 +- .../FileTime.App.Search/SearchTask.cs | 2 + .../IConsoleAppState.cs | 1 - .../FileTime.ConsoleUI.App/ConsoleAppState.cs | 1 - src/ConsoleApp/FileTime.ConsoleUI/Program.cs | 4 +- .../Interactions/IOptionsInputElement.cs | 2 +- .../FileTime.Core.Command/Copy/CopyCommand.cs | 2 +- src/Library/CircularBuffer/CircularBuffer.cs | 83 ++++++------------- .../DeclarativeProperty/CombineAllProperty.cs | 4 +- .../DeclarativeProperty.cs | 5 +- .../DeclarativePropertyBase.cs | 4 +- .../DeclarativePropertyExtensions.cs | 36 ++++---- .../DeclarativeProperty/MapProperty.cs | 12 +-- src/Library/TerminalUI/Binding.cs | 2 +- src/Library/TerminalUI/Controls/Grid.cs | 12 +-- src/Library/TerminalUI/Controls/TextBox.cs | 2 +- src/Library/TerminalUI/Controls/View.cs | 3 +- .../ExpressionTrackers/ConditionalTracker.cs | 2 +- .../ExpressionTrackerBase.cs | 2 +- .../TerminalUI/Extensions/ViewExtensions.cs | 4 +- src/Library/TerminalUI/RenderEngine.cs | 1 - src/Library/TerminalUI/Traits/IFocusable.cs | 4 +- .../RootDriveInfo.cs | 8 +- .../LocalContentProvider.cs | 2 + .../AdminElevationConfiguration.cs | 2 +- .../CompressionUserCommandHandler.cs | 2 +- 34 files changed, 119 insertions(+), 183 deletions(-) diff --git a/src/AppCommon/FileTime.App.ContainerSizeScanner/ContainerSizeSizeScanProvider.cs b/src/AppCommon/FileTime.App.ContainerSizeScanner/ContainerSizeSizeScanProvider.cs index 9b6c4cb..dd7d452 100644 --- a/src/AppCommon/FileTime.App.ContainerSizeScanner/ContainerSizeSizeScanProvider.cs +++ b/src/AppCommon/FileTime.App.ContainerSizeScanner/ContainerSizeSizeScanProvider.cs @@ -23,7 +23,7 @@ public class ContainerSizeSizeScanProvider : ContentProviderBase, IContainerSize _serviceProvider = serviceProvider; } - public override async Task GetItemByFullNameAsync( + public override Task GetItemByFullNameAsync( FullName fullName, PointInTime pointInTime, bool forceResolve = false, @@ -32,14 +32,14 @@ public class ContainerSizeSizeScanProvider : ContentProviderBase, IContainerSize ) { if (fullName.Path == ContentProviderName) - return this; + return Task.FromResult((IItem)this); var pathParts = fullName.Path.Split(Constants.SeparatorChar); var item = _sizeScanTasks.FirstOrDefault(t => t.SizeSizeScanContainer.Name == pathParts[1])?.SizeSizeScanContainer; if (pathParts.Length == 2) - return item ?? throw new ItemNotFoundException(fullName); + return Task.FromResult((IItem)item!) ?? throw new ItemNotFoundException(fullName); for (var i = 2; i < pathParts.Length - 1 && item != null; i++) { @@ -47,22 +47,8 @@ public class ContainerSizeSizeScanProvider : ContentProviderBase, IContainerSize item = item.ChildContainers.FirstOrDefault(c => c.Name == childName); } - if (item is not null) - { - var childItem = item.SizeItems.FirstOrDefault(c => c.Name == pathParts[^1]); - if (childItem is not null) return childItem; - - /*var childName = item.RealContainer.FullName?.GetChild(pathParts[^1]); - if (childName is null) throw new ItemNotFoundException(fullName); - - return await _timelessContentProvider.GetItemByFullNameAsync( - childName, - pointInTime, - forceResolve, - forceResolvePathType, - itemInitializationSettings - );*/ - } + var childItem = item?.SizeItems.FirstOrDefault(c => c.Name == pathParts[^1]); + if (childItem != null) return Task.FromResult((IItem)childItem); throw new ItemNotFoundException(fullName); } diff --git a/src/AppCommon/FileTime.App.Core.Abstraction/ViewModels/ITabViewModel.cs b/src/AppCommon/FileTime.App.Core.Abstraction/ViewModels/ITabViewModel.cs index 9c85c09..b4a1856 100644 --- a/src/AppCommon/FileTime.App.Core.Abstraction/ViewModels/ITabViewModel.cs +++ b/src/AppCommon/FileTime.App.Core.Abstraction/ViewModels/ITabViewModel.cs @@ -17,8 +17,8 @@ public interface ITabViewModel : IInitable, IDisposable IDeclarativeProperty CurrentSelectedItemAsContainer { get; } IDeclarativeProperty?> CurrentItems { get; } IDeclarativeProperty> MarkedItems { get; } - IDeclarativeProperty> SelectedsChildren { get; } - IDeclarativeProperty> ParentsChildren { get; } + IDeclarativeProperty?> SelectedsChildren { get; } + IDeclarativeProperty?> ParentsChildren { get; } IDeclarativeProperty CurrentSelectedItemIndex { get; set; } void ClearMarkedItems(); diff --git a/src/AppCommon/FileTime.App.Core/Services/DialogServiceBase.cs b/src/AppCommon/FileTime.App.Core/Services/DialogServiceBase.cs index cad7c13..40b7f45 100644 --- a/src/AppCommon/FileTime.App.Core/Services/DialogServiceBase.cs +++ b/src/AppCommon/FileTime.App.Core/Services/DialogServiceBase.cs @@ -8,8 +8,8 @@ namespace FileTime.App.Core.Services; public abstract class DialogServiceBase : IDialogServiceBase { private readonly IModalService _modalService; - private OcConsumer _readInputConsumer = new(); - private OcConsumer _lastMessageBoxConsumer = new(); + private readonly OcConsumer _readInputConsumer = new(); + private readonly OcConsumer _lastMessageBoxConsumer = new(); public ScalarComputing ReadInput { get; } public ScalarComputing LastMessageBox { get; } @@ -20,14 +20,14 @@ public abstract class DialogServiceBase : IDialogServiceBase .OpenModals .OfTypeComputing() .FirstComputing() - .For(_readInputConsumer); + .For(_readInputConsumer)!; LastMessageBox = modalService .OpenModals .OfTypeComputing() .LastComputing() - .For(_lastMessageBoxConsumer); + .For(_lastMessageBoxConsumer)!; } private void ReadInputs( diff --git a/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs b/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs index 48a4ed1..751c01c 100644 --- a/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs +++ b/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs @@ -166,7 +166,7 @@ public class TabPersistenceService : ITabPersistenceService } var tab = await _serviceProvider - .GetAsyncInitableResolver(currentDirectory ?? _localContentProvider) + .GetAsyncInitableResolver(currentDirectory ?? _localContentProvider) .GetRequiredServiceAsync(); var tabViewModel = _serviceProvider.GetInitableResolver(tab, 1).GetRequiredService(); @@ -191,8 +191,8 @@ public class TabPersistenceService : ITabPersistenceService if (tab.Path == null) continue; if (_contentProvidersNotToRestore.Any(p => tab.Path.StartsWith(p))) continue; - IContainer? container = null; - var path = FullName.CreateSafe(tab.Path); + IContainer? container; + var path = FullName.CreateSafe(tab.Path)!; while (true) { try @@ -213,7 +213,7 @@ public class TabPersistenceService : ITabPersistenceService } catch { - path = path?.GetParent(); + path = path.GetParent(); if (path == null) { throw new Exception($"Could not find an initializable path along {tab.Path}"); diff --git a/src/AppCommon/FileTime.App.Core/Services/RapidTravelModeKeyInputHandler.cs b/src/AppCommon/FileTime.App.Core/Services/RapidTravelModeKeyInputHandler.cs index cec4e6d..bdd3327 100644 --- a/src/AppCommon/FileTime.App.Core/Services/RapidTravelModeKeyInputHandler.cs +++ b/src/AppCommon/FileTime.App.Core/Services/RapidTravelModeKeyInputHandler.cs @@ -91,7 +91,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler if (selectedCommandBinding != null) { args.Handled = true; - await CallCommandAsync(_identifiableUserCommandService.GetCommand(selectedCommandBinding.Command)); + await CallCommandAsync(_identifiableUserCommandService.GetCommand(selectedCommandBinding.Command)!); } } } diff --git a/src/AppCommon/FileTime.App.Core/ViewModels/AppStateBase.cs b/src/AppCommon/FileTime.App.Core/ViewModels/AppStateBase.cs index 94d5d4b..83b4e02 100644 --- a/src/AppCommon/FileTime.App.Core/ViewModels/AppStateBase.cs +++ b/src/AppCommon/FileTime.App.Core/ViewModels/AppStateBase.cs @@ -47,10 +47,10 @@ public abstract partial class AppStateBase : IAppState SearchText = _searchText.AsObservable(); SelectedTab = DeclarativePropertyHelpers.CombineLatest, ITabViewModel, ITabViewModel>( - _tabs.Watch(), - _selectedTab, - (tabs, selectedTab) => Task.FromResult(GetSelectedTab(tabs, selectedTab)) - ); + _tabs.Watch()!, + _selectedTab!, + (tabs, selectedTab) => Task.FromResult(GetSelectedTab(tabs, selectedTab)!) + )!; Tabs = new ReadOnlyObservableCollection(_tabs); @@ -58,7 +58,7 @@ public abstract partial class AppStateBase : IAppState .Map(t => t?.CurrentLocation) .Switch() .Map(c => c?.GetExtension()?.GetStatusProperty()) - .Switch(); + .Switch()!; } public void AddTab(ITabViewModel tabViewModel) diff --git a/src/AppCommon/FileTime.App.Core/ViewModels/ItemViewModel.cs b/src/AppCommon/FileTime.App.Core/ViewModels/ItemViewModel.cs index e187d7c..7685139 100644 --- a/src/AppCommon/FileTime.App.Core/ViewModels/ItemViewModel.cs +++ b/src/AppCommon/FileTime.App.Core/ViewModels/ItemViewModel.cs @@ -45,7 +45,7 @@ public abstract partial class ItemViewModel : IItemViewModel var sourceCollection = itemViewModelType switch { - ItemViewModelType.Main => parentTab.CurrentItems, + ItemViewModelType.Main => parentTab.CurrentItems!, ItemViewModelType.Parent => parentTab.ParentsChildren, ItemViewModelType.SelectedChild => parentTab.SelectedsChildren, _ => throw new InvalidEnumArgumentException() @@ -59,15 +59,15 @@ public abstract partial class ItemViewModel : IItemViewModel ? (IReadOnlyList) await nameConverterProvider.GetItemNamePartsAsync(item) : _itemNameConverterService.GetDisplayName(item.DisplayName, s) ), - _ => new DeclarativeProperty>(new List {new(item.DisplayName)}), + _ => new DeclarativeProperty>(new List {new(item.DisplayName)})!, }; BaseItem = item; - DisplayName = displayName; + DisplayName = displayName!; DisplayNameText = item.DisplayName; IsMarked = itemViewModelType is ItemViewModelType.Main - ? parentTab.MarkedItems.Map(m => m.Any(i => i.Path == item.FullName?.Path)) + ? parentTab.MarkedItems!.Map(m => m!.Any(i => i.Path == item.FullName?.Path)) : new DeclarativeProperty(false); IsSelected = itemViewModelType is ItemViewModelType.Main @@ -78,7 +78,7 @@ public abstract partial class ItemViewModel : IItemViewModel : new DeclarativeProperty(IsInDeepestPath()); IsAlternative = sourceCollection - .Debounce(TimeSpan.FromMilliseconds(100)) + .Debounce(TimeSpan.FromMilliseconds(100))! .Map(c => c?.Index().FirstOrDefault(i => EqualsTo(i.Value)).Key % 2 == 1 ); diff --git a/src/AppCommon/FileTime.App.Core/ViewModels/TabViewModel.cs b/src/AppCommon/FileTime.App.Core/ViewModels/TabViewModel.cs index 6bb1590..dd88281 100644 --- a/src/AppCommon/FileTime.App.Core/ViewModels/TabViewModel.cs +++ b/src/AppCommon/FileTime.App.Core/ViewModels/TabViewModel.cs @@ -21,7 +21,6 @@ namespace FileTime.App.Core.ViewModels; public partial class TabViewModel : ITabViewModel { private readonly IServiceProvider _serviceProvider; - private readonly IAppState _appState; private readonly ITimelessContentProvider _timelessContentProvider; private readonly IRefreshSmoothnessCalculator _refreshSmoothnessCalculator; private readonly ObservableCollection _markedItems = new(); @@ -34,16 +33,16 @@ public partial class TabViewModel : ITabViewModel public ITab? Tab { get; private set; } public int TabNumber { get; private set; } - public IDeclarativeProperty IsSelected { get; } + public IDeclarativeProperty IsSelected { get; } = null!; - public IDeclarativeProperty CurrentLocation { get; private set; } - public IDeclarativeProperty CurrentSelectedItem { get; private set; } - public IDeclarativeProperty CurrentSelectedItemIndex { get; set; } - public IDeclarativeProperty CurrentSelectedItemAsContainer { get; private set; } - public IDeclarativeProperty?> CurrentItems { get; private set; } - public IDeclarativeProperty> MarkedItems { get; } - public IDeclarativeProperty?> SelectedsChildren { get; private set; } - public IDeclarativeProperty?> ParentsChildren { get; private set; } + public IDeclarativeProperty CurrentLocation { get; private set; } = null!; + public IDeclarativeProperty CurrentSelectedItem { get; private set; } = null!; + public IDeclarativeProperty CurrentSelectedItemIndex { get; set; } = null!; + public IDeclarativeProperty CurrentSelectedItemAsContainer { get; private set; } = null!; + public IDeclarativeProperty?> CurrentItems { get; private set; } = null!; + public IDeclarativeProperty> MarkedItems { get; } = null!; + public IDeclarativeProperty?> SelectedsChildren { get; private set; } = null!; + public IDeclarativeProperty?> ParentsChildren { get; private set; } = null!; public TabViewModel( @@ -53,10 +52,9 @@ public partial class TabViewModel : ITabViewModel IRefreshSmoothnessCalculator refreshSmoothnessCalculator) { _serviceProvider = serviceProvider; - _appState = appState; - MarkedItems = _markedItems.Watch(); - IsSelected = _appState.SelectedTab.Map(s => s == this); + MarkedItems = _markedItems.Watch()!; + IsSelected = appState.SelectedTab.Map(s => s == this); _timelessContentProvider = timelessContentProvider; _refreshSmoothnessCalculator = refreshSmoothnessCalculator; } @@ -117,7 +115,7 @@ public partial class TabViewModel : ITabViewModel return Task.FromResult(-1); }); - CurrentSelectedItem.Subscribe((v) => + CurrentSelectedItem.Subscribe(_ => { _refreshSmoothnessCalculator.RegisterChange(); _refreshSmoothnessCalculator.RecalculateSmoothness(); @@ -176,12 +174,6 @@ public partial class TabViewModel : ITabViewModel computing.For(consumer); } - private static SortExpressionComparer SortItems() - //TODO: Order - => SortExpressionComparer - .Ascending(i => i.BaseItem?.Type ?? AbsolutePathType.Unknown) - .ThenByAscending(i => i.DisplayNameText?.ToLower() ?? ""); - private static IItem MapItem(AbsolutePath item) { var t = Task.Run(async () => diff --git a/src/AppCommon/FileTime.App.FrequencyNavigation/ViewModels/FrequencyNavigationViewModel.cs b/src/AppCommon/FileTime.App.FrequencyNavigation/ViewModels/FrequencyNavigationViewModel.cs index a028aca..e17720d 100644 --- a/src/AppCommon/FileTime.App.FrequencyNavigation/ViewModels/FrequencyNavigationViewModel.cs +++ b/src/AppCommon/FileTime.App.FrequencyNavigation/ViewModels/FrequencyNavigationViewModel.cs @@ -37,7 +37,7 @@ public class FrequencyNavigationViewModel : FuzzyPanelViewModel, IFreque if (keyEventArgs.Key == Keys.Enter) { keyEventArgs.Handled = true; - var targetContainer = await _timelessContentProvider.GetItemByFullNameAsync(new FullName(SelectedItem), PointInTime.Present); + var targetContainer = await _timelessContentProvider.GetItemByFullNameAsync(new FullName(SelectedItem!), PointInTime.Present); var openContainerCommand = new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, targetContainer)); await _userCommandHandlerService.HandleCommandAsync(openContainerCommand); Close(); diff --git a/src/AppCommon/FileTime.App.Search/SearchTask.cs b/src/AppCommon/FileTime.App.Search/SearchTask.cs index ad879c7..b16d685 100644 --- a/src/AppCommon/FileTime.App.Search/SearchTask.cs +++ b/src/AppCommon/FileTime.App.Search/SearchTask.cs @@ -71,7 +71,9 @@ public class SearchTask : ISearchTask _isSearching = true; _searchingLock.Release(); +#pragma warning disable CS4014 Task.Run(BootstrapSearch); +#pragma warning restore CS4014 async Task BootstrapSearch() { diff --git a/src/ConsoleApp/FileTime.ConsoleUI.App.Abstractions/IConsoleAppState.cs b/src/ConsoleApp/FileTime.ConsoleUI.App.Abstractions/IConsoleAppState.cs index 2c1e305..5f1a0c4 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI.App.Abstractions/IConsoleAppState.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI.App.Abstractions/IConsoleAppState.cs @@ -6,7 +6,6 @@ namespace FileTime.ConsoleUI.App; public interface IConsoleAppState : IAppState { - string ErrorText { get; set; } ObservableCollection PopupTexts { get; } ItemPreviewType? PreviewType { get; set; } } \ No newline at end of file diff --git a/src/ConsoleApp/FileTime.ConsoleUI.App/ConsoleAppState.cs b/src/ConsoleApp/FileTime.ConsoleUI.App/ConsoleAppState.cs index b25e2d8..1d8819b 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI.App/ConsoleAppState.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI.App/ConsoleAppState.cs @@ -7,7 +7,6 @@ namespace FileTime.ConsoleUI.App; public partial class ConsoleAppState : AppStateBase, IConsoleAppState { - [Notify] private string? _errorText; //TODO: make it thread safe public ObservableCollection PopupTexts { get; } = new(); diff --git a/src/ConsoleApp/FileTime.ConsoleUI/Program.cs b/src/ConsoleApp/FileTime.ConsoleUI/Program.cs index bd1337f..987fc6c 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI/Program.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI/Program.cs @@ -140,6 +140,6 @@ static bool HandleInfoProviders(string[] args, IServiceProvider serviceProvider) public partial class Program { - public static string AppDataRoot { get; private set; } - public static string EnvironmentName { get; private set; } + public static string AppDataRoot { get; private set; } = null!; + public static string EnvironmentName { get; private set; } = null!; } \ No newline at end of file diff --git a/src/Core/FileTime.Core.Abstraction/Interactions/IOptionsInputElement.cs b/src/Core/FileTime.Core.Abstraction/Interactions/IOptionsInputElement.cs index afa0b23..0732f41 100644 --- a/src/Core/FileTime.Core.Abstraction/Interactions/IOptionsInputElement.cs +++ b/src/Core/FileTime.Core.Abstraction/Interactions/IOptionsInputElement.cs @@ -2,6 +2,6 @@ namespace FileTime.Core.Interactions; public interface IOptionsInputElement : IInputElement { - object Value { get; set; } + object? Value { get; set; } IReadOnlyCollection Options { get; } } \ No newline at end of file diff --git a/src/Core/FileTime.Core.Command/Copy/CopyCommand.cs b/src/Core/FileTime.Core.Command/Copy/CopyCommand.cs index 88ffe1d..589c4e3 100644 --- a/src/Core/FileTime.Core.Command/Copy/CopyCommand.cs +++ b/src/Core/FileTime.Core.Command/Copy/CopyCommand.cs @@ -153,7 +153,7 @@ public class CopyCommand : CommandBase, ITransportationCommand var statusList = statuses.ToList(); var done = statusList.Count(s => s) + 1; if (done > statusList.Count) done = statusList.Count; - + return Task.FromResult($"Copy - {done} / {statusList.Count}"); }) .Subscribe(async (v, _) => await SetDisplayLabelAsync(v)); diff --git a/src/Library/CircularBuffer/CircularBuffer.cs b/src/Library/CircularBuffer/CircularBuffer.cs index b0230a3..edbbf7e 100644 --- a/src/Library/CircularBuffer/CircularBuffer.cs +++ b/src/Library/CircularBuffer/CircularBuffer.cs @@ -325,32 +325,20 @@ public class CircularBuffer : ICircularBuffer } /// - public int Capacity - { - get { return _buffer.Length; } - } + public int Capacity => _buffer.Length; /// - public bool IsFull - { - get { return Count == Capacity; } - } + public bool IsFull => Count == Capacity; /// - public bool IsEmpty - { - get { return Count == 0; } - } + public bool IsEmpty => Count == 0; /// [Obsolete("Use Count property instead")] public int Size => Count; /// - public int Count - { - get { return _size; } - } + public int Count => _size; /// [Obsolete("Use First() method instead")] @@ -381,30 +369,30 @@ public class CircularBuffer : ICircularBuffer { if (IsEmpty) { - throw new IndexOutOfRangeException(string.Format("Cannot access index {0}. Buffer is empty", index)); + throw new IndexOutOfRangeException($"Cannot access index {index}. Buffer is empty"); } if (index >= _size) { - throw new IndexOutOfRangeException(string.Format("Cannot access index {0}. Buffer size is {1}", index, _size)); + throw new IndexOutOfRangeException($"Cannot access index {index}. Buffer size is {_size}"); } - int actualIndex = InternalIndex(index); + var actualIndex = InternalIndex(index); return _buffer[actualIndex]; } set { if (IsEmpty) { - throw new IndexOutOfRangeException(string.Format("Cannot access index {0}. Buffer is empty", index)); + throw new IndexOutOfRangeException($"Cannot access index {index}. Buffer is empty"); } if (index >= _size) { - throw new IndexOutOfRangeException(string.Format("Cannot access index {0}. Buffer size is {1}", index, _size)); + throw new IndexOutOfRangeException($"Cannot access index {index}. Buffer size is {_size}"); } - int actualIndex = InternalIndex(index); + var actualIndex = InternalIndex(index); _buffer[actualIndex] = value; } } @@ -449,7 +437,7 @@ public class CircularBuffer : ICircularBuffer ThrowIfEmpty("Cannot take elements from an empty buffer."); Decrement(ref _end); var value = _buffer[_start]; - _buffer[_end] = default(T); + _buffer[_end] = default!; --_size; return value; } @@ -459,7 +447,7 @@ public class CircularBuffer : ICircularBuffer { ThrowIfEmpty("Cannot take elements from an empty buffer."); var value = _buffer[_start]; - _buffer[_start] = default(T); + _buffer[_start] = default!; Increment(ref _start); --_size; return value; @@ -478,7 +466,7 @@ public class CircularBuffer : ICircularBuffer /// public T[] ToArray() { - T[] newArray = new T[Count]; + var newArray = new T[Count]; CopyToInternal(newArray, 0); return newArray; } @@ -553,24 +541,15 @@ public class CircularBuffer : ICircularBuffer #endif /// - public IList> ToArraySegments() - { - return new[] {ArrayOne(), ArrayTwo()}; - } + public IList> ToArraySegments() => new[] {ArrayOne(), ArrayTwo()}; #if (NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER) /// - public SpanTuple ToSpan() - { - return new SpanTuple(SpanOne(), SpanTwo()); - } + public SpanTuple ToSpan() => new(SpanOne(), SpanTwo()); /// - public (ReadOnlyMemory A, ReadOnlyMemory B) ToMemory() - { - return (MemoryOne(), MemoryTwo()); - } + public (ReadOnlyMemory A, ReadOnlyMemory B) ToMemory() => (MemoryOne(), MemoryTwo()); #endif @@ -583,11 +562,11 @@ public class CircularBuffer : ICircularBuffer public IEnumerator GetEnumerator() { var segments = ToArraySegments(); - foreach (ArraySegment segment in segments) + foreach (var segment in segments) { - for (int i = 0; i < segment.Count; i++) + for (var i = 0; i < segment.Count; i++) { - yield return segment.Array[segment.Offset + i]; + yield return segment.Array![segment.Offset + i]; } } } @@ -596,24 +575,15 @@ public class CircularBuffer : ICircularBuffer #region IEnumerable implementation - IEnumerator IEnumerable.GetEnumerator() - { - return (IEnumerator) GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #endregion #if (NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER) - private void CopyToInternal(T[] array, int index) - { - CopyToInternal(array.AsSpan(index)); - } + private void CopyToInternal(T[] array, int index) => CopyToInternal(array.AsSpan(index)); - private void CopyToInternal(Memory memory) - { - CopyToInternal(memory.Span); - } + private void CopyToInternal(Memory memory) => CopyToInternal(memory.Span); private void CopyToInternal(Span span) { @@ -639,10 +609,10 @@ public class CircularBuffer : ICircularBuffer { var segments = ToArraySegments(); var segment = segments[0]; - Array.Copy(segment.Array, segment.Offset, array, index, segment.Count); + Array.Copy(segment.Array!, segment.Offset, array, index, segment.Count); index += segment.Count; segment = segments[1]; - Array.Copy(segment.Array, segment.Offset, array, index, segment.Count); + Array.Copy(segment.Array!, segment.Offset, array, index, segment.Count); } private void ThrowIfEmpty(string message = "Cannot access an empty buffer.") @@ -690,10 +660,7 @@ public class CircularBuffer : ICircularBuffer /// /// External index. /// - private int InternalIndex(int index) - { - return _start + (index < (Capacity - _start) ? index : index - Capacity); - } + private int InternalIndex(int index) => _start + (index < (Capacity - _start) ? index : index - Capacity); // doing ArrayOne and ArrayTwo methods returning ArraySegment as seen here: // http://www.boost.org/doc/libs/1_37_0/libs/circular_buffer/doc/circular_buffer.html#classboost_1_1circular__buffer_1957cccdcb0c4ef7d80a34a990065818d diff --git a/src/Library/DeclarativeProperty/CombineAllProperty.cs b/src/Library/DeclarativeProperty/CombineAllProperty.cs index 4ee8c0b..89236b0 100644 --- a/src/Library/DeclarativeProperty/CombineAllProperty.cs +++ b/src/Library/DeclarativeProperty/CombineAllProperty.cs @@ -14,7 +14,7 @@ public class CombineAllProperty : DeclarativePropertyBase _sources = sourcesList; _combiner = combiner; - var initialValueTask = _combiner(sourcesList.Select(p => p.Value)); + var initialValueTask = _combiner(sourcesList.Select(p => p.Value)!); initialValueTask.Wait(); SetNewValueSync(initialValueTask.Result); @@ -29,7 +29,7 @@ public class CombineAllProperty : DeclarativePropertyBase private async Task Update() { var values = _sources.Select(p => p.Value); - var result = await _combiner(values); + var result = await _combiner(values!); await SetNewValueAsync(result); } diff --git a/src/Library/DeclarativeProperty/DeclarativeProperty.cs b/src/Library/DeclarativeProperty/DeclarativeProperty.cs index 84edf2a..a101871 100644 --- a/src/Library/DeclarativeProperty/DeclarativeProperty.cs +++ b/src/Library/DeclarativeProperty/DeclarativeProperty.cs @@ -7,7 +7,7 @@ public static class DeclarativePropertyHelpers IDeclarativeProperty prop2, Func> func, Action? setValueHook = null) - => new(prop1, prop2, func, setValueHook); + => new(prop1, prop2, func!, setValueHook); public static CombineLatestProperty CombineLatest( IDeclarativeProperty prop1, @@ -15,7 +15,7 @@ public static class DeclarativePropertyHelpers IDeclarativeProperty prop3, Func> func, Action? setValueHook = null) - => new(prop1, prop2, prop3, func, setValueHook); + => new(prop1, prop2, prop3, func!, setValueHook); public static MergeProperty Merge(params IDeclarativeProperty[] props) => new(props); @@ -46,6 +46,7 @@ public sealed class DeclarativeProperty : DeclarativePropertyBase } catch { + // ignored } }); } diff --git a/src/Library/DeclarativeProperty/DeclarativePropertyBase.cs b/src/Library/DeclarativeProperty/DeclarativePropertyBase.cs index 55fb65b..b7b9878 100644 --- a/src/Library/DeclarativeProperty/DeclarativePropertyBase.cs +++ b/src/Library/DeclarativeProperty/DeclarativePropertyBase.cs @@ -70,7 +70,7 @@ public abstract class DeclarativePropertyBase : IDeclarativeProperty { lock (_subscriberLock) { - _subscribers.Remove(onChange); + _subscribers.Remove(onChange!); } } @@ -95,7 +95,7 @@ public abstract class DeclarativePropertyBase : IDeclarativeProperty IDisposable IObservable.Subscribe(IObserver observer) => Subscribe((v, _) => { - observer.OnNext(v); + observer.OnNext(v!); return Task.CompletedTask; }); diff --git a/src/Library/DeclarativeProperty/DeclarativePropertyExtensions.cs b/src/Library/DeclarativeProperty/DeclarativePropertyExtensions.cs index 179ba7a..f7b53f9 100644 --- a/src/Library/DeclarativeProperty/DeclarativePropertyExtensions.cs +++ b/src/Library/DeclarativeProperty/DeclarativePropertyExtensions.cs @@ -21,14 +21,14 @@ public static class DeclarativePropertyExtensions public static IDeclarativeProperty DistinctUntilChanged(this IDeclarativeProperty from) => new DistinctUntilChangedProperty(from); - public static IDeclarativeProperty Map(this IDeclarativeProperty from, Func> mapper) - => new MapProperty(mapper, from); + public static IDeclarativeProperty Map(this IDeclarativeProperty from, Func> mapper) + => new MapProperty(mapper, from); public static IDeclarativeProperty Map(this IDeclarativeProperty from, Func mapper) => new MapProperty((next, _) => Task.FromResult(mapper(next)), from); - public static async Task> MapAsync(this IDeclarativeProperty from, Func> mapper) - => await MapProperty.CreateAsync(mapper, from); + public static async Task> MapAsync(this IDeclarativeProperty from, Func> mapper) + => await MapProperty.CreateAsync(mapper, from); public static async Task> MapAsync(this IDeclarativeProperty from, Func mapper) => await MapProperty.CreateAsync((next, _) => Task.FromResult(mapper(next)), from); @@ -65,38 +65,38 @@ public static class DeclarativePropertyExtensions ) => new ExtractorProperty(from, extractor); - public static IDeclarativeProperty Watch( + public static IDeclarativeProperty Watch( this IDeclarativeProperty collection) where TCollection : IList, INotifyCollectionChanged - => new CollectionRepeaterProperty(collection); + => new CollectionRepeaterProperty(collection); - public static IDeclarativeProperty Watch( + public static IDeclarativeProperty Watch( this TCollection collection) where TCollection : IList, INotifyCollectionChanged - => new CollectionRepeaterProperty(collection); + => new CollectionRepeaterProperty(collection); - public static IDeclarativeProperty?> Watch( + public static IDeclarativeProperty> Watch( this ObservableCollection collection) - => new CollectionRepeaterProperty?, TItem>(collection); + => new CollectionRepeaterProperty, TItem>(collection); - public static IDeclarativeProperty?> Watch( + public static IDeclarativeProperty> Watch( this ReadOnlyObservableCollection collection) - => new CollectionRepeaterProperty?, TItem>(collection); + => new CollectionRepeaterProperty, TItem>(collection); - public static IDeclarativeProperty CombineLatest( + public static IDeclarativeProperty CombineLatest( this IDeclarativeProperty prop1, IDeclarativeProperty prop2, Func> func, Action? setValueHook = null) - => new CombineLatestProperty(prop1, prop2, func, setValueHook); + => new CombineLatestProperty(prop1, prop2, func!, setValueHook); - public static IDeclarativeProperty Switch(this IDeclarativeProperty?> from) - => new SwitchProperty(from); + public static IDeclarativeProperty Switch(this IDeclarativeProperty?> from) + => new SwitchProperty(from); - public static IDeclarativeProperty CombineAll( + public static IDeclarativeProperty CombineAll( this IEnumerable> sources, Func, Task> combiner, Action? setValueHook = null) - => new CombineAllProperty(sources, combiner, setValueHook); + => new CombineAllProperty(sources, combiner, setValueHook); } \ No newline at end of file diff --git a/src/Library/DeclarativeProperty/MapProperty.cs b/src/Library/DeclarativeProperty/MapProperty.cs index 715703b..2526beb 100644 --- a/src/Library/DeclarativeProperty/MapProperty.cs +++ b/src/Library/DeclarativeProperty/MapProperty.cs @@ -2,10 +2,10 @@ public sealed class MapProperty : DeclarativePropertyBase { - private readonly Func> _mapper; + private readonly Func> _mapper; public MapProperty( - Func> mapper, + Func> mapper, IDeclarativeProperty from, Action? setValueHook = null) : base(setValueHook) { @@ -15,16 +15,16 @@ public sealed class MapProperty : DeclarativePropertyBase private async Task SetValue(TFrom? next, CancellationToken cancellationToken = default) { - var newValue = await _mapper(next, cancellationToken); + var newValue = await _mapper(next!, cancellationToken); await SetNewValueAsync(newValue, cancellationToken); } - public static async Task> CreateAsync( - Func> mapper, + public static async Task> CreateAsync( + Func> mapper, IDeclarativeProperty from, Action? setValueHook = null) { - var prop = new MapProperty(mapper, from, setValueHook); + var prop = new MapProperty(mapper, from, setValueHook); await prop.SetValue(from.Value); return prop; diff --git a/src/Library/TerminalUI/Binding.cs b/src/Library/TerminalUI/Binding.cs index 142688b..2cc7a48 100644 --- a/src/Library/TerminalUI/Binding.cs +++ b/src/Library/TerminalUI/Binding.cs @@ -72,7 +72,7 @@ public sealed class Binding : Property { if (couldCompute) { - value = _converter(_dataContextMapper(_dataSourceView.DataContext)); + value = _converter(_dataContextMapper(_dataSourceView.DataContext!)); } else { diff --git a/src/Library/TerminalUI/Controls/Grid.cs b/src/Library/TerminalUI/Controls/Grid.cs index 7922371..622b38d 100644 --- a/src/Library/TerminalUI/Controls/Grid.cs +++ b/src/Library/TerminalUI/Controls/Grid.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Logging; using TerminalUI.Extensions; using TerminalUI.Models; @@ -339,17 +340,6 @@ public sealed class Grid : ChildCollectionView, T>, IVisibilityChange return (x, y); } - private void WithCalculatedSize(in RenderContext renderContext, Option size, WithSizes actionWithSizes) - { - WithCalculatedSize(renderContext, size, Helper); - - object? Helper(in RenderContext renderContext1, ReadOnlySpan widths, ReadOnlySpan heights) - { - actionWithSizes(renderContext1, widths, heights); - return null; - } - } - private TResult WithCalculatedSize(in RenderContext renderContext, Option size, WithSizes actionWithSizes) { //TODO: Optimize it, dont calculate all of these, only if there is Auto value(s) diff --git a/src/Library/TerminalUI/Controls/TextBox.cs b/src/Library/TerminalUI/Controls/TextBox.cs index 9a6b9f8..d8e274c 100644 --- a/src/Library/TerminalUI/Controls/TextBox.cs +++ b/src/Library/TerminalUI/Controls/TextBox.cs @@ -60,7 +60,7 @@ public sealed partial class TextBox : View, T>, IFocusable, IDispl ((INotifyPropertyChanged) this).PropertyChanged += OnPropertyChangedEventHandler; } - private void OnPropertyChangedEventHandler(object sender, PropertyChangedEventArgs args) + private void OnPropertyChangedEventHandler(object? sender, PropertyChangedEventArgs args) { if (args.PropertyName == nameof(Text)) { diff --git a/src/Library/TerminalUI/Controls/View.cs b/src/Library/TerminalUI/Controls/View.cs index c7d6216..4eb58f7 100644 --- a/src/Library/TerminalUI/Controls/View.cs +++ b/src/Library/TerminalUI/Controls/View.cs @@ -2,6 +2,7 @@ using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using GeneralInputKey; using PropertyChanged.SourceGenerator; @@ -14,6 +15,7 @@ namespace TerminalUI.Controls; public delegate string TextTransformer(string text, Position position, Size size); +[SuppressMessage("Performance", "EPS02:Non-readonly struct used as in-parameter")] public abstract partial class View : IView where TConcrete : View { private readonly List _disposables = new(); @@ -511,7 +513,6 @@ public abstract partial class View : IView where TConcrete : Vi ProcessParentKeyHandlers(keyEventArgs); } - protected void ProcessKeyHandlers(GeneralKeyEventArgs keyEventArgs) { foreach (var keyHandler in KeyHandlers) diff --git a/src/Library/TerminalUI/ExpressionTrackers/ConditionalTracker.cs b/src/Library/TerminalUI/ExpressionTrackers/ConditionalTracker.cs index c636f97..638c8a5 100644 --- a/src/Library/TerminalUI/ExpressionTrackers/ConditionalTracker.cs +++ b/src/Library/TerminalUI/ExpressionTrackers/ConditionalTracker.cs @@ -38,7 +38,7 @@ public class ConditionalTracker : ExpressionTrackerBase { true => _ifTrueExpressionTracker.GetValue(), false => _ifFalseExpressionTracker.GetValue(), - _ => throw new NotSupportedException($"Conditional expression must evaluate to a boolean value, but {testValue} ({testValue.GetType().Name}) is not that.") + _ => throw new NotSupportedException($"Conditional expression must evaluate to a boolean value, but {testValue} ({testValue?.GetType().Name}) is not that.") }; } } \ No newline at end of file diff --git a/src/Library/TerminalUI/ExpressionTrackers/ExpressionTrackerBase.cs b/src/Library/TerminalUI/ExpressionTrackers/ExpressionTrackerBase.cs index 4901364..ded0aae 100644 --- a/src/Library/TerminalUI/ExpressionTrackers/ExpressionTrackerBase.cs +++ b/src/Library/TerminalUI/ExpressionTrackers/ExpressionTrackerBase.cs @@ -68,7 +68,7 @@ public abstract class ExpressionTrackerBase : IExpressionTracker useNull = true; } } - catch (Exception e) + catch (Exception) { useNull = true; } diff --git a/src/Library/TerminalUI/Extensions/ViewExtensions.cs b/src/Library/TerminalUI/Extensions/ViewExtensions.cs index c741866..2c49a0a 100644 --- a/src/Library/TerminalUI/Extensions/ViewExtensions.cs +++ b/src/Library/TerminalUI/Extensions/ViewExtensions.cs @@ -35,11 +35,11 @@ public static class ViewExtensions Expression> dataSourceExpression, Action handler) { - new PropertyChangedHandler + _ = new PropertyChangedHandler ( dataSource, dataSourceExpression, - handler + handler! ); return dataSource; diff --git a/src/Library/TerminalUI/RenderEngine.cs b/src/Library/TerminalUI/RenderEngine.cs index 28d38e6..d770397 100644 --- a/src/Library/TerminalUI/RenderEngine.cs +++ b/src/Library/TerminalUI/RenderEngine.cs @@ -19,7 +19,6 @@ public class RenderEngine : IRenderEngine private bool[,]? _updatedCells; private bool[,]? _filledCells; private bool[,]? _lastFilledCells; - private DateTime _renderRequestDetected; private ITheme? _lastTheme; public RenderEngine(IApplicationContext applicationContext, IEventLoop eventLoop) diff --git a/src/Library/TerminalUI/Traits/IFocusable.cs b/src/Library/TerminalUI/Traits/IFocusable.cs index cec0d8b..a8ccd6d 100644 --- a/src/Library/TerminalUI/Traits/IFocusable.cs +++ b/src/Library/TerminalUI/Traits/IFocusable.cs @@ -1,5 +1,4 @@ -using GeneralInputKey; -using TerminalUI.ConsoleDrivers; +using TerminalUI.ConsoleDrivers; using TerminalUI.Controls; namespace TerminalUI.Traits; @@ -9,5 +8,4 @@ public interface IFocusable : IView void Focus(); void UnFocus(); void SetCursorPosition(IConsoleDriver consoleDriver); - void HandleKeyInput(GeneralKeyEventArgs keyEventArgs); } \ No newline at end of file diff --git a/src/Providers/FileTime.Providers.Local.Abstractions/RootDriveInfo.cs b/src/Providers/FileTime.Providers.Local.Abstractions/RootDriveInfo.cs index f24824a..450e68b 100644 --- a/src/Providers/FileTime.Providers.Local.Abstractions/RootDriveInfo.cs +++ b/src/Providers/FileTime.Providers.Local.Abstractions/RootDriveInfo.cs @@ -15,13 +15,13 @@ public partial class RootDriveInfo [Notify] private string? _label; - [Notify] private long _size = 0; + [Notify] private long _size; - [Notify] private long _free = 0; + [Notify] private long _free; - [Notify] private long _used = 0; + [Notify] private long _used; - [Notify] public long UsedPercentage => Size == 0 ? 0 : Used * 100 / Size; + public long UsedPercentage => Size == 0 ? 0 : Used * 100 / Size; public FullName Path { get; } diff --git a/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs b/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs index 5803300..3ff67e1 100644 --- a/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs +++ b/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs @@ -298,7 +298,9 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo var lockObj = new object(); var loadingIndicatorCancellation = new CancellationTokenSource(); +#pragma warning disable CS4014 Task.Run(async () => await DelayedLoadingIndicator()); +#pragma warning restore CS4014 await LoadChildrenInternal(); lock (lockObj) diff --git a/src/Providers/FileTime.Providers.LocalAdmin.Abstractions/AdminElevationConfiguration.cs b/src/Providers/FileTime.Providers.LocalAdmin.Abstractions/AdminElevationConfiguration.cs index 5063d20..e2fa07b 100644 --- a/src/Providers/FileTime.Providers.LocalAdmin.Abstractions/AdminElevationConfiguration.cs +++ b/src/Providers/FileTime.Providers.LocalAdmin.Abstractions/AdminElevationConfiguration.cs @@ -4,7 +4,7 @@ public class AdminElevationConfiguration { public const string SectionName = "AdminElevation"; public string? ServerExecutablePath { get; set; } - public string LinuxElevationTool { get; set; } + public string LinuxElevationTool { get; set; } = null!; public int? ServerPort { get; set; } public bool? StartProcess { get; set; } } \ No newline at end of file diff --git a/src/Tools/FileTime.Tools.Compression/CompressionUserCommandHandler.cs b/src/Tools/FileTime.Tools.Compression/CompressionUserCommandHandler.cs index 51b48f1..8c830f3 100644 --- a/src/Tools/FileTime.Tools.Compression/CompressionUserCommandHandler.cs +++ b/src/Tools/FileTime.Tools.Compression/CompressionUserCommandHandler.cs @@ -20,7 +20,7 @@ public class CompressionUserCommandHandler : AggregatedUserCommandHandler IClipboardService clipboardService) { _clipboardService = clipboardService; - _markedItems = appState.SelectedTab.Map(t => t?.MarkedItems).Switch(); + _markedItems = appState.SelectedTab.Map(t => t?.MarkedItems)!.Switch(); _selectedItem = appState.SelectedTab.Map(t => t?.CurrentSelectedItem).Switch(); AddCommandHandler(new IUserCommandHandler[]