Browse Source

Remove nullable and cref warnings.

Dariusz Komosinski 5 years ago
parent
commit
128fbee51f

+ 1 - 3
src/Avalonia.Base/AvaloniaProperty.cs

@@ -159,8 +159,6 @@ namespace Avalonia
         /// </summary>
         internal int Id { get; }
 
-        internal bool HasChangedSubscriptions => _changed?.HasObservers ?? false;
-
         /// <summary>
         /// Provides access to a property's binding via the <see cref="AvaloniaObject"/>
         /// indexer.
@@ -512,7 +510,7 @@ namespace Avalonia
         /// <returns>
         /// An <see cref="IDisposable"/> if setting the property can be undone, otherwise null.
         /// </returns>
-        internal abstract IDisposable? RouteSetValue(
+        internal abstract IDisposable RouteSetValue(
             IAvaloniaObject o,
             object value,
             BindingPriority priority);

+ 2 - 2
src/Avalonia.Base/AvaloniaPropertyRegistry.cs

@@ -362,7 +362,7 @@ namespace Avalonia
         /// <param name="property">The property.</param>
         /// <remarks>
         /// You won't usually want to call this method directly, instead use the
-        /// <see cref="AvaloniaProperty.Register{TOwner, TValue}(string, TValue, bool, Data.BindingMode, Func{TOwner, TValue, TValue}, Action{IAvaloniaObject, bool})"/>
+        /// <see cref="AvaloniaProperty.Register{TOwner, TValue}(string, TValue, bool, Data.BindingMode, Func{TValue, bool}, Func{IAvaloniaObject, TValue, TValue}, Action{IAvaloniaObject, bool})"/>
         /// method.
         /// </remarks>
         public void Register(Type type, AvaloniaProperty property)
@@ -413,7 +413,7 @@ namespace Avalonia
         /// <param name="property">The property.</param>
         /// <remarks>
         /// You won't usually want to call this method directly, instead use the
-        /// <see cref="AvaloniaProperty.RegisterAttached{THost, TValue}(string, Type, TValue, bool, Data.BindingMode, Func{THost, TValue, TValue})"/>
+        /// <see cref="AvaloniaProperty.RegisterAttached{THost, TValue}(string, Type, TValue, bool, Data.BindingMode, Func{TValue, bool}, Func{IAvaloniaObject, TValue, TValue})"/>
         /// method.
         /// </remarks>
         public void RegisterAttached(Type type, AvaloniaProperty property)

+ 2 - 0
src/Avalonia.Base/Collections/Pooled/IReadOnlyPooledList.cs

@@ -13,9 +13,11 @@ namespace Avalonia.Collections.Pooled
 
     public interface IReadOnlyPooledList<T> : IReadOnlyList<T>
     {
+#pragma warning disable CS0419
         /// <summary>
         /// Gets a <see cref="System.ReadOnlySpan{T}"/> for the items currently in the collection.
         /// </summary>
+#pragma warning restore CS0419
         ReadOnlySpan<T> Span { get; }
     }
 }

+ 2 - 1
src/Avalonia.Base/Collections/Pooled/PooledList.cs

@@ -138,7 +138,6 @@ namespace Avalonia.Collections.Pooled
         /// initially empty, but will have room for the given number of elements
         /// before any reallocations are required.
         /// </summary>
-        /// <param name="sizeToCapacity">If true, Count of list equals capacity. Depending on ClearMode, rented items may or may not hold dirty values.</param>
         public PooledList(int capacity, ClearMode clearMode, ArrayPool<T> customPool, bool sizeToCapacity)
         {
             if (capacity < 0)
@@ -499,11 +498,13 @@ namespace Avalonia.Collections.Pooled
         public void AddRange(T[] array)
             => AddRange(array.AsSpan());
 
+#pragma warning disable CS0419
         /// <summary>
         /// Adds the elements of the given <see cref="ReadOnlySpan{T}"/> to the end of this list. If
         /// required, the capacity of the list is increased to twice the previous
         /// capacity or the new size, whichever is larger.
         /// </summary>
+#pragma warning restore CS0419
         public void AddRange(ReadOnlySpan<T> span)
         {
             var newSpan = InsertSpan(_size, span.Length, false);

+ 18 - 18
src/Avalonia.Base/Data/BindingValue.cs

@@ -190,7 +190,7 @@ namespace Avalonia.Data
         /// Gets the value of the binding value if present, otherwise the default value.
         /// </summary>
         /// <returns>The value.</returns>
-        public T GetValueOrDefault() => HasValue ? _value : default;
+        public T GetValueOrDefault() => HasValue ? _value : default!;
 
         /// <summary>
         /// Gets the value of the binding value if present, otherwise a default value.
@@ -209,8 +209,8 @@ namespace Avalonia.Data
         public TResult GetValueOrDefault<TResult>()
         {
             return HasValue ?
-                _value is TResult result ? result : default
-                : default;
+                _value is TResult result ? result : default!
+                : default!;
         }
 
         /// <summary>
@@ -225,7 +225,7 @@ namespace Avalonia.Data
         public TResult GetValueOrDefault<TResult>(TResult defaultValue)
         {
             return HasValue ?
-                _value is TResult result ? result : default
+                _value is TResult result ? result : default!
                 : defaultValue;
         }
 
@@ -242,7 +242,7 @@ namespace Avalonia.Data
                 UnsetValueType _ => Unset,
                 DoNothingType _ => DoNothing,
                 BindingNotification n => n.ToBindingValue().Cast<T>(),
-                _ => (T)value
+                _ => (T)value!
             };
         }
 
@@ -259,18 +259,18 @@ namespace Avalonia.Data
 
         public static implicit operator BindingValue<T>(Optional<T> optional)
         {
-            return optional.HasValue ? optional.Value : Unset;
+            return optional.HasValue ? optional.Value! : Unset;
         }
 
         /// <summary>
         /// Returns a binding value with a type of <see cref="BindingValueType.UnsetValue"/>.
         /// </summary>
-        public static BindingValue<T> Unset => new BindingValue<T>(BindingValueType.UnsetValue, default, null);
+        public static BindingValue<T> Unset => new BindingValue<T>(BindingValueType.UnsetValue, default!, null);
 
         /// <summary>
         /// Returns a binding value with a type of <see cref="BindingValueType.DoNothing"/>.
         /// </summary>
-        public static BindingValue<T> DoNothing => new BindingValue<T>(BindingValueType.DoNothing, default, null);
+        public static BindingValue<T> DoNothing => new BindingValue<T>(BindingValueType.DoNothing, default!, null);
 
         /// <summary>
         /// Returns a binding value with a type of <see cref="BindingValueType.BindingError"/>.
@@ -278,9 +278,9 @@ namespace Avalonia.Data
         /// <param name="e">The binding error.</param>
         public static BindingValue<T> BindingError(Exception e)
         {
-            e = e ?? throw new ArgumentNullException("e");
+            e = e ?? throw new ArgumentNullException(nameof(e));
 
-            return new BindingValue<T>(BindingValueType.BindingError, default, e);
+            return new BindingValue<T>(BindingValueType.BindingError, default!, e);
         }
 
         /// <summary>
@@ -290,7 +290,7 @@ namespace Avalonia.Data
         /// <param name="fallbackValue">The fallback value.</param>
         public static BindingValue<T> BindingError(Exception e, T fallbackValue)
         {
-            e = e ?? throw new ArgumentNullException("e");
+            e = e ?? throw new ArgumentNullException(nameof(e));
 
             return new BindingValue<T>(BindingValueType.BindingErrorWithFallback, fallbackValue, e);
         }
@@ -303,13 +303,13 @@ namespace Avalonia.Data
         /// <param name="fallbackValue">The fallback value.</param>
         public static BindingValue<T> BindingError(Exception e, Optional<T> fallbackValue)
         {
-            e = e ?? throw new ArgumentNullException("e");
+            e = e ?? throw new ArgumentNullException(nameof(e));
 
             return new BindingValue<T>(
                 fallbackValue.HasValue ?
                     BindingValueType.BindingErrorWithFallback :
                     BindingValueType.BindingError,
-                fallbackValue.HasValue ? fallbackValue.Value : default,
+                fallbackValue.HasValue ? fallbackValue.Value : default!,
                 e);
         }
 
@@ -319,9 +319,9 @@ namespace Avalonia.Data
         /// <param name="e">The data validation error.</param>
         public static BindingValue<T> DataValidationError(Exception e)
         {
-            e = e ?? throw new ArgumentNullException("e");
+            e = e ?? throw new ArgumentNullException(nameof(e));
 
-            return new BindingValue<T>(BindingValueType.DataValidationError, default, e);
+            return new BindingValue<T>(BindingValueType.DataValidationError, default!, e);
         }
 
         /// <summary>
@@ -331,7 +331,7 @@ namespace Avalonia.Data
         /// <param name="fallbackValue">The fallback value.</param>
         public static BindingValue<T> DataValidationError(Exception e, T fallbackValue)
         {
-            e = e ?? throw new ArgumentNullException("e");
+            e = e ?? throw new ArgumentNullException(nameof(e));
 
             return new BindingValue<T>(BindingValueType.DataValidationErrorWithFallback, fallbackValue, e);
         }
@@ -344,13 +344,13 @@ namespace Avalonia.Data
         /// <param name="fallbackValue">The fallback value.</param>
         public static BindingValue<T> DataValidationError(Exception e, Optional<T> fallbackValue)
         {
-            e = e ?? throw new ArgumentNullException("e");
+            e = e ?? throw new ArgumentNullException(nameof(e));
 
             return new BindingValue<T>(
                 fallbackValue.HasValue ?
                     BindingValueType.DataValidationErrorWithFallback :
                     BindingValueType.DataValidationError,
-                fallbackValue.HasValue ? fallbackValue.Value : default,
+                fallbackValue.HasValue ? fallbackValue.Value : default!,
                 e);
         }
 

+ 5 - 5
src/Avalonia.Base/Data/Optional.cs

@@ -60,7 +60,7 @@ namespace Avalonia.Data
         /// Casts the value (if any) to an <see cref="object"/>.
         /// </summary>
         /// <returns>The cast optional value.</returns>
-        public Optional<object> ToObject() => HasValue ? new Optional<object>(_value) : default;
+        public Optional<object> ToObject() => HasValue ? new Optional<object>(_value!) : default;
 
         /// <inheritdoc/>
         public override string ToString() => HasValue ? _value?.ToString() ?? "(null)" : "(empty)";
@@ -69,7 +69,7 @@ namespace Avalonia.Data
         /// Gets the value if present, otherwise the default value.
         /// </summary>
         /// <returns>The value.</returns>
-        public T GetValueOrDefault() => HasValue ? _value : default;
+        public T GetValueOrDefault() => HasValue ? _value : default!;
 
         /// <summary>
         /// Gets the value if present, otherwise a default value.
@@ -88,8 +88,8 @@ namespace Avalonia.Data
         public TResult GetValueOrDefault<TResult>()
         {
             return HasValue ?
-                _value is TResult result ? result : default
-                : default;
+                _value is TResult result ? result : default!
+                : default!;
         }
 
         /// <summary>
@@ -104,7 +104,7 @@ namespace Avalonia.Data
         public TResult GetValueOrDefault<TResult>(TResult defaultValue)
         {
             return HasValue ?
-                _value is TResult result ? result : default
+                _value is TResult result ? result : default!
                 : defaultValue;
         }
 

+ 1 - 1
src/Avalonia.Base/DirectPropertyBase.cs

@@ -122,7 +122,7 @@ namespace Avalonia
 
         internal override object RouteGetBaseValue(IAvaloniaObject o, BindingPriority maxPriority)
         {
-            return o.GetValue<TValue>(this);
+            return o.GetValue<TValue>(this)!;
         }
 
         /// <inheritdoc/>

+ 0 - 2
src/Avalonia.Base/IStyledPropertyMetadata.cs

@@ -1,5 +1,3 @@
-using System;
-
 namespace Avalonia
 {
     /// <summary>

+ 2 - 2
src/Avalonia.Base/PropertyStore/LocalValueEntry.cs

@@ -15,11 +15,11 @@ namespace Avalonia.PropertyStore
 
         public LocalValueEntry(T value) => _value = value;
         public BindingPriority Priority => BindingPriority.LocalValue;
-        Optional<object> IValue.GetValue() => new Optional<object>(_value);
+        Optional<object> IValue.GetValue() => new Optional<object>(_value!);
         
         public Optional<T> GetValue(BindingPriority maxPriority)
         {
-            return BindingPriority.LocalValue >= maxPriority ? _value : Optional<T>.Empty;
+            return BindingPriority.LocalValue >= maxPriority ? _value! : Optional<T>.Empty;
         }
 
         public void SetValue(T value) => _value = value;

+ 1 - 2
src/Avalonia.Base/StyledPropertyMetadata`1.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Diagnostics;
 using Avalonia.Data;
 
 namespace Avalonia
@@ -35,7 +34,7 @@ namespace Avalonia
         /// <summary>
         /// Gets the value coercion callback, if any.
         /// </summary>
-        public Func<IAvaloniaObject, TValue, TValue>? CoerceValue { get; private set; }
+        public Func<IAvaloniaObject, TValue, TValue> CoerceValue { get; private set; }
 
         object IStyledPropertyMetadata.DefaultValue => DefaultValue;
 

+ 1 - 1
src/Avalonia.Base/ValueStore.cs

@@ -162,7 +162,7 @@ namespace Avalonia
                         _sink.ValueChanged(new AvaloniaPropertyChangedEventArgs<T>(
                             _owner,
                             property,
-                            old,
+                            old!,
                             default,
                             BindingPriority.Unset));
                     }