Cleaning up warning

This commit is contained in:
2023-09-05 21:22:30 +02:00
parent ecfd0d1b93
commit e6fd8d4ab5
34 changed files with 119 additions and 183 deletions

View File

@@ -325,32 +325,20 @@ public class CircularBuffer<T> : ICircularBuffer<T>
}
/// <inheritdoc/>
public int Capacity
{
get { return _buffer.Length; }
}
public int Capacity => _buffer.Length;
/// <inheritdoc/>
public bool IsFull
{
get { return Count == Capacity; }
}
public bool IsFull => Count == Capacity;
/// <inheritdoc/>
public bool IsEmpty
{
get { return Count == 0; }
}
public bool IsEmpty => Count == 0;
/// <inheritdoc/>
[Obsolete("Use Count property instead")]
public int Size => Count;
/// <inheritdoc/>
public int Count
{
get { return _size; }
}
public int Count => _size;
/// <inheritdoc/>
[Obsolete("Use First() method instead")]
@@ -381,30 +369,30 @@ public class CircularBuffer<T> : ICircularBuffer<T>
{
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<T> : ICircularBuffer<T>
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<T> : ICircularBuffer<T>
{
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<T> : ICircularBuffer<T>
/// <inheritdoc/>
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<T> : ICircularBuffer<T>
#endif
/// <inheritdoc/>
public IList<ArraySegment<T>> ToArraySegments()
{
return new[] {ArrayOne(), ArrayTwo()};
}
public IList<ArraySegment<T>> ToArraySegments() => new[] {ArrayOne(), ArrayTwo()};
#if (NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER)
/// <inheritdoc/>
public SpanTuple<T> ToSpan()
{
return new SpanTuple<T>(SpanOne(), SpanTwo());
}
public SpanTuple<T> ToSpan() => new(SpanOne(), SpanTwo());
/// <inheritdoc/>
public (ReadOnlyMemory<T> A, ReadOnlyMemory<T> B) ToMemory()
{
return (MemoryOne(), MemoryTwo());
}
public (ReadOnlyMemory<T> A, ReadOnlyMemory<T> B) ToMemory() => (MemoryOne(), MemoryTwo());
#endif
@@ -583,11 +562,11 @@ public class CircularBuffer<T> : ICircularBuffer<T>
public IEnumerator<T> GetEnumerator()
{
var segments = ToArraySegments();
foreach (ArraySegment<T> 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<T> : ICircularBuffer<T>
#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<T> memory)
{
CopyToInternal(memory.Span);
}
private void CopyToInternal(Memory<T> memory) => CopyToInternal(memory.Span);
private void CopyToInternal(Span<T> span)
{
@@ -639,10 +609,10 @@ public class CircularBuffer<T> : ICircularBuffer<T>
{
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<T> : ICircularBuffer<T>
/// <param name='index'>
/// External index.
/// </param>
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<T> as seen here:
// http://www.boost.org/doc/libs/1_37_0/libs/circular_buffer/doc/circular_buffer.html#classboost_1_1circular__buffer_1957cccdcb0c4ef7d80a34a990065818d

View File

@@ -14,7 +14,7 @@ public class CombineAllProperty<T, TResult> : DeclarativePropertyBase<TResult>
_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<T, TResult> : DeclarativePropertyBase<TResult>
private async Task Update()
{
var values = _sources.Select(p => p.Value);
var result = await _combiner(values);
var result = await _combiner(values!);
await SetNewValueAsync(result);
}

View File

@@ -7,7 +7,7 @@ public static class DeclarativePropertyHelpers
IDeclarativeProperty<T2> prop2,
Func<T1, T2, Task<TResult>> func,
Action<TResult?>? setValueHook = null)
=> new(prop1, prop2, func, setValueHook);
=> new(prop1, prop2, func!, setValueHook);
public static CombineLatestProperty<T1, T2, T3, TResult> CombineLatest<T1, T2, T3, TResult>(
IDeclarativeProperty<T1> prop1,
@@ -15,7 +15,7 @@ public static class DeclarativePropertyHelpers
IDeclarativeProperty<T3> prop3,
Func<T1, T2, T3, Task<TResult>> func,
Action<TResult?>? setValueHook = null)
=> new(prop1, prop2, prop3, func, setValueHook);
=> new(prop1, prop2, prop3, func!, setValueHook);
public static MergeProperty<T> Merge<T>(params IDeclarativeProperty<T>[] props)
=> new(props);
@@ -46,6 +46,7 @@ public sealed class DeclarativeProperty<T> : DeclarativePropertyBase<T>
}
catch
{
// ignored
}
});
}

View File

@@ -70,7 +70,7 @@ public abstract class DeclarativePropertyBase<T> : IDeclarativeProperty<T>
{
lock (_subscriberLock)
{
_subscribers.Remove(onChange);
_subscribers.Remove(onChange!);
}
}
@@ -95,7 +95,7 @@ public abstract class DeclarativePropertyBase<T> : IDeclarativeProperty<T>
IDisposable IObservable<T>.Subscribe(IObserver<T> observer)
=> Subscribe((v, _) =>
{
observer.OnNext(v);
observer.OnNext(v!);
return Task.CompletedTask;
});

View File

@@ -21,14 +21,14 @@ public static class DeclarativePropertyExtensions
public static IDeclarativeProperty<T> DistinctUntilChanged<T>(this IDeclarativeProperty<T> from)
=> new DistinctUntilChangedProperty<T>(from);
public static IDeclarativeProperty<TTo?> Map<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, CancellationToken, Task<TTo?>> mapper)
=> new MapProperty<TFrom?, TTo?>(mapper, from);
public static IDeclarativeProperty<TTo> Map<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, CancellationToken, Task<TTo?>> mapper)
=> new MapProperty<TFrom?, TTo>(mapper, from);
public static IDeclarativeProperty<TTo?> Map<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, TTo?> mapper)
=> new MapProperty<TFrom?, TTo?>((next, _) => Task.FromResult(mapper(next)), from);
public static async Task<IDeclarativeProperty<TTo?>> MapAsync<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, CancellationToken, Task<TTo?>> mapper)
=> await MapProperty<TFrom?, TTo?>.CreateAsync(mapper, from);
public static async Task<IDeclarativeProperty<TTo>> MapAsync<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, CancellationToken, Task<TTo?>> mapper)
=> await MapProperty<TFrom, TTo>.CreateAsync(mapper, from);
public static async Task<IDeclarativeProperty<TTo?>> MapAsync<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, TTo?> mapper)
=> await MapProperty<TFrom?, TTo?>.CreateAsync((next, _) => Task.FromResult(mapper(next)), from);
@@ -65,38 +65,38 @@ public static class DeclarativePropertyExtensions
)
=> new ExtractorProperty<T>(from, extractor);
public static IDeclarativeProperty<TCollection?> Watch<TCollection, TItem>(
public static IDeclarativeProperty<TCollection> Watch<TCollection, TItem>(
this IDeclarativeProperty<TCollection?> collection)
where TCollection : IList<TItem>, INotifyCollectionChanged
=> new CollectionRepeaterProperty<TCollection?, TItem>(collection);
=> new CollectionRepeaterProperty<TCollection, TItem>(collection);
public static IDeclarativeProperty<TCollection?> Watch<TCollection, TItem>(
public static IDeclarativeProperty<TCollection> Watch<TCollection, TItem>(
this TCollection collection)
where TCollection : IList<TItem>, INotifyCollectionChanged
=> new CollectionRepeaterProperty<TCollection?, TItem>(collection);
=> new CollectionRepeaterProperty<TCollection, TItem>(collection);
public static IDeclarativeProperty<ObservableCollection<TItem>?> Watch<TItem>(
public static IDeclarativeProperty<ObservableCollection<TItem>> Watch<TItem>(
this ObservableCollection<TItem> collection)
=> new CollectionRepeaterProperty<ObservableCollection<TItem>?, TItem>(collection);
=> new CollectionRepeaterProperty<ObservableCollection<TItem>, TItem>(collection);
public static IDeclarativeProperty<ReadOnlyObservableCollection<TItem>?> Watch<TItem>(
public static IDeclarativeProperty<ReadOnlyObservableCollection<TItem>> Watch<TItem>(
this ReadOnlyObservableCollection<TItem> collection)
=> new CollectionRepeaterProperty<ReadOnlyObservableCollection<TItem>?, TItem>(collection);
=> new CollectionRepeaterProperty<ReadOnlyObservableCollection<TItem>, TItem>(collection);
public static IDeclarativeProperty<TResult?> CombineLatest<T1, T2, TResult>(
public static IDeclarativeProperty<TResult> CombineLatest<T1, T2, TResult>(
this IDeclarativeProperty<T1> prop1,
IDeclarativeProperty<T2> prop2,
Func<T1, T2, Task<TResult?>> func,
Action<TResult?>? setValueHook = null)
=> new CombineLatestProperty<T1,T2,TResult?>(prop1, prop2, func, setValueHook);
=> new CombineLatestProperty<T1,T2,TResult>(prop1, prop2, func!, setValueHook);
public static IDeclarativeProperty<T> Switch<T>(this IDeclarativeProperty<IDeclarativeProperty<T>?> from)
=> new SwitchProperty<T>(from);
public static IDeclarativeProperty<T?> Switch<T>(this IDeclarativeProperty<IDeclarativeProperty<T?>?> from)
=> new SwitchProperty<T?>(from);
public static IDeclarativeProperty<TResult?> CombineAll<T, TResult>(
public static IDeclarativeProperty<TResult> CombineAll<T, TResult>(
this IEnumerable<IDeclarativeProperty<T>> sources,
Func<IEnumerable<T>, Task<TResult?>> combiner,
Action<TResult?>? setValueHook = null)
=> new CombineAllProperty<T,TResult?>(sources, combiner, setValueHook);
=> new CombineAllProperty<T,TResult>(sources, combiner, setValueHook);
}

View File

@@ -2,10 +2,10 @@
public sealed class MapProperty<TFrom, TTo> : DeclarativePropertyBase<TTo>
{
private readonly Func<TFrom?, CancellationToken, Task<TTo?>> _mapper;
private readonly Func<TFrom, CancellationToken, Task<TTo>> _mapper;
public MapProperty(
Func<TFrom?, CancellationToken, Task<TTo?>> mapper,
Func<TFrom, CancellationToken, Task<TTo>> mapper,
IDeclarativeProperty<TFrom?> from,
Action<TTo?>? setValueHook = null) : base(setValueHook)
{
@@ -15,16 +15,16 @@ public sealed class MapProperty<TFrom, TTo> : DeclarativePropertyBase<TTo>
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<MapProperty<TFrom?, TTo?>> CreateAsync(
Func<TFrom?, CancellationToken, Task<TTo?>> mapper,
public static async Task<MapProperty<TFrom, TTo>> CreateAsync(
Func<TFrom, CancellationToken, Task<TTo>> mapper,
IDeclarativeProperty<TFrom?> from,
Action<TTo?>? setValueHook = null)
{
var prop = new MapProperty<TFrom?, TTo?>(mapper, from, setValueHook);
var prop = new MapProperty<TFrom, TTo>(mapper, from, setValueHook);
await prop.SetValue(from.Value);
return prop;

View File

@@ -72,7 +72,7 @@ public sealed class Binding<TDataContext, TExpressionResult, TResult> : Property
{
if (couldCompute)
{
value = _converter(_dataContextMapper(_dataSourceView.DataContext));
value = _converter(_dataContextMapper(_dataSourceView.DataContext!));
}
else
{

View File

@@ -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<T> : ChildCollectionView<Grid<T>, T>, IVisibilityChange
return (x, y);
}
private void WithCalculatedSize(in RenderContext renderContext, Option<Size> size, WithSizes actionWithSizes)
{
WithCalculatedSize(renderContext, size, Helper);
object? Helper(in RenderContext renderContext1, ReadOnlySpan<int> widths, ReadOnlySpan<int> heights)
{
actionWithSizes(renderContext1, widths, heights);
return null;
}
}
private TResult WithCalculatedSize<TResult>(in RenderContext renderContext, Option<Size> size, WithSizes<TResult> actionWithSizes)
{
//TODO: Optimize it, dont calculate all of these, only if there is Auto value(s)

View File

@@ -60,7 +60,7 @@ public sealed partial class TextBox<T> : View<TextBox<T>, 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))
{

View File

@@ -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<TConcrete, T> : IView<T> where TConcrete : View<TConcrete, T>
{
private readonly List<IDisposable> _disposables = new();
@@ -511,7 +513,6 @@ public abstract partial class View<TConcrete, T> : IView<T> where TConcrete : Vi
ProcessParentKeyHandlers(keyEventArgs);
}
protected void ProcessKeyHandlers(GeneralKeyEventArgs keyEventArgs)
{
foreach (var keyHandler in KeyHandlers)

View File

@@ -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.")
};
}
}

View File

@@ -68,7 +68,7 @@ public abstract class ExpressionTrackerBase : IExpressionTracker
useNull = true;
}
}
catch (Exception e)
catch (Exception)
{
useNull = true;
}

View File

@@ -35,11 +35,11 @@ public static class ViewExtensions
Expression<Func<TItem, TExpressionResult>> dataSourceExpression,
Action<bool, TExpressionResult> handler)
{
new PropertyChangedHandler<TItem, TExpressionResult>
_ = new PropertyChangedHandler<TItem, TExpressionResult>
(
dataSource,
dataSourceExpression,
handler
handler!
);
return dataSource;

View File

@@ -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)

View File

@@ -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);
}