Browse Source

Finished adding nullable annotations to Avalonia.Base.

pull/7179/head
Steven Kirk 4 years ago
parent
commit
76667dbd0d
  1. 2
      src/Avalonia.Base/AttachedProperty.cs
  2. 1
      src/Avalonia.Base/Avalonia.Base.csproj
  3. 2
      src/Avalonia.Base/AvaloniaInternalException.cs
  4. 19
      src/Avalonia.Base/AvaloniaLocator.cs
  5. 6
      src/Avalonia.Base/AvaloniaObject.cs
  6. 2
      src/Avalonia.Base/AvaloniaObjectExtensions.cs
  7. 6
      src/Avalonia.Base/AvaloniaProperty.cs
  8. 2
      src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs
  9. 2
      src/Avalonia.Base/AvaloniaPropertyChangedEventArgs`1.cs
  10. 2
      src/Avalonia.Base/AvaloniaPropertyMetadata.cs
  11. 2
      src/Avalonia.Base/AvaloniaPropertyRegistry.cs
  12. 10
      src/Avalonia.Base/AvaloniaProperty`1.cs
  13. 18
      src/Avalonia.Base/Collections/AvaloniaDictionary.cs
  14. 6
      src/Avalonia.Base/Collections/AvaloniaList.cs
  15. 13
      src/Avalonia.Base/Collections/AvaloniaListConverter.cs
  16. 16
      src/Avalonia.Base/Collections/AvaloniaListExtensions.cs
  17. 2
      src/Avalonia.Base/Collections/IAvaloniaList.cs
  18. 2
      src/Avalonia.Base/Collections/IAvaloniaReadOnlyList.cs
  19. 8
      src/Avalonia.Base/Collections/NotifyCollectionChangedExtensions.cs
  20. 2
      src/Avalonia.Base/Collections/Pooled/ClearMode.cs
  21. 2
      src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs
  22. 2
      src/Avalonia.Base/Collections/Pooled/IReadOnlyPooledList.cs
  23. 17
      src/Avalonia.Base/Collections/Pooled/PooledList.cs
  24. 4
      src/Avalonia.Base/Collections/Pooled/PooledStack.cs
  25. 2
      src/Avalonia.Base/Collections/Pooled/StackDebugView.cs
  26. 2
      src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs
  27. 2
      src/Avalonia.Base/Data/AssignBindingAttribute.cs
  28. 2
      src/Avalonia.Base/Data/BindingChainException.cs
  29. 2
      src/Avalonia.Base/Data/BindingMode.cs
  30. 8
      src/Avalonia.Base/Data/BindingNotification.cs
  31. 2
      src/Avalonia.Base/Data/BindingOperations.cs
  32. 2
      src/Avalonia.Base/Data/BindingPriority.cs
  33. 8
      src/Avalonia.Base/Data/BindingValue.cs
  34. 2
      src/Avalonia.Base/Data/Converters/BoolConverters.cs
  35. 4
      src/Avalonia.Base/Data/Converters/DefaultValueConverter.cs
  36. 2
      src/Avalonia.Base/Data/Converters/FuncMultiValueConverter.cs
  37. 2
      src/Avalonia.Base/Data/Converters/FuncValueConverter.cs
  38. 2
      src/Avalonia.Base/Data/Converters/IMultiValueConverter.cs
  39. 2
      src/Avalonia.Base/Data/Converters/IValueConverter.cs
  40. 38
      src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs
  41. 2
      src/Avalonia.Base/Data/Converters/ObjectConverters.cs
  42. 2
      src/Avalonia.Base/Data/Converters/StringConverters.cs
  43. 2
      src/Avalonia.Base/Data/Converters/StringFormatMultiValueConverter.cs
  44. 2
      src/Avalonia.Base/Data/Converters/StringFormatValueConverter.cs
  45. 2
      src/Avalonia.Base/Data/Core/AvaloniaPropertyAccessorNode.cs
  46. 4
      src/Avalonia.Base/Data/Core/BindingExpression.cs
  47. 6
      src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs
  48. 2
      src/Avalonia.Base/Data/Core/CommonPropertyNames.cs
  49. 4
      src/Avalonia.Base/Data/Core/EmptyExpressionNode.cs
  50. 2
      src/Avalonia.Base/Data/Core/ExpressionNode.cs
  51. 2
      src/Avalonia.Base/Data/Core/ExpressionObserver.cs
  52. 2
      src/Avalonia.Base/Data/Core/ExpressionParseException.cs
  53. 2
      src/Avalonia.Base/Data/Core/IPropertyInfo.cs
  54. 4
      src/Avalonia.Base/Data/Core/ITransformNode.cs
  55. 4
      src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs
  56. 8
      src/Avalonia.Base/Data/Core/IndexerNodeBase.cs
  57. 2
      src/Avalonia.Base/Data/Core/LogicalNotNode.cs
  58. 2
      src/Avalonia.Base/Data/Core/MarkupBindingChainException.cs
  59. 2
      src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs
  60. 18
      src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs
  61. 9
      src/Avalonia.Base/Data/Core/Plugins/AvaloniaPropertyAccessorPlugin.cs
  62. 16
      src/Avalonia.Base/Data/Core/Plugins/DataAnnotationsValidationPlugin.cs
  63. 2
      src/Avalonia.Base/Data/Core/Plugins/DataValidationBase.cs
  64. 4
      src/Avalonia.Base/Data/Core/Plugins/ExceptionValidationPlugin.cs
  65. 2
      src/Avalonia.Base/Data/Core/Plugins/IDataValidationPlugin.cs
  66. 2
      src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessor.cs
  67. 2
      src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessorPlugin.cs
  68. 2
      src/Avalonia.Base/Data/Core/Plugins/IStreamPlugin.cs
  69. 4
      src/Avalonia.Base/Data/Core/Plugins/IndeiValidationPlugin.cs
  70. 4
      src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs
  71. 2
      src/Avalonia.Base/Data/Core/Plugins/MethodAccessorPlugin.cs
  72. 8
      src/Avalonia.Base/Data/Core/Plugins/ObservableStreamPlugin.cs
  73. 2
      src/Avalonia.Base/Data/Core/Plugins/PropertyAccessorBase.cs
  74. 2
      src/Avalonia.Base/Data/Core/Plugins/PropertyError.cs
  75. 4
      src/Avalonia.Base/Data/Core/Plugins/TaskStreamPlugin.cs
  76. 2
      src/Avalonia.Base/Data/Core/PropertyAccessorNode.cs
  77. 2
      src/Avalonia.Base/Data/Core/PropertyPath.cs
  78. 2
      src/Avalonia.Base/Data/Core/SettableNode.cs
  79. 2
      src/Avalonia.Base/Data/Core/StreamBindingExtensions.cs
  80. 2
      src/Avalonia.Base/Data/Core/StreamNode.cs
  81. 2
      src/Avalonia.Base/Data/Core/TypeCastNode.cs
  82. 2
      src/Avalonia.Base/Data/DataValidationException.cs
  83. 2
      src/Avalonia.Base/Data/IBinding.cs
  84. 4
      src/Avalonia.Base/Data/IndexerBinding.cs
  85. 2
      src/Avalonia.Base/Data/IndexerDescriptor.cs
  86. 2
      src/Avalonia.Base/Data/InstancedBinding.cs
  87. 2
      src/Avalonia.Base/Data/Optional.cs
  88. 8
      src/Avalonia.Base/Diagnostics/AvaloniaPropertyValue.cs
  89. 2
      src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs
  90. 2
      src/Avalonia.Base/Diagnostics/INotifyCollectionChangedDebug.cs
  91. 2
      src/Avalonia.Base/DirectProperty.cs
  92. 4
      src/Avalonia.Base/DirectPropertyBase.cs
  93. 2
      src/Avalonia.Base/DirectPropertyMetadata`1.cs
  94. 2
      src/Avalonia.Base/EnumExtensions.cs
  95. 2
      src/Avalonia.Base/IAvaloniaObject.cs
  96. 2
      src/Avalonia.Base/IDescription.cs
  97. 2
      src/Avalonia.Base/IDirectPropertyAccessor.cs
  98. 2
      src/Avalonia.Base/IDirectPropertyMetadata.cs
  99. 2
      src/Avalonia.Base/IStyledPropertyAccessor.cs
  100. 2
      src/Avalonia.Base/IStyledPropertyMetadata.cs

2
src/Avalonia.Base/AttachedProperty.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia
{
/// <summary>

1
src/Avalonia.Base/Avalonia.Base.csproj

@ -11,4 +11,5 @@
<Import Project="..\..\build\JetBrains.Annotations.props" />
<Import Project="..\..\build\System.Memory.props" />
<Import Project="..\..\build\ApiDiff.props" />
<Import Project="..\..\build\NullableEnable.props" />
</Project>

2
src/Avalonia.Base/AvaloniaInternalException.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia
{
/// <summary>

19
src/Avalonia.Base/AvaloniaLocator.cs

@ -7,10 +7,10 @@ namespace Avalonia
{
public class AvaloniaLocator : IAvaloniaDependencyResolver
{
private readonly IAvaloniaDependencyResolver _parentScope;
private readonly IAvaloniaDependencyResolver? _parentScope;
public static IAvaloniaDependencyResolver Current { get; set; }
public static AvaloniaLocator CurrentMutable { get; set; }
private readonly Dictionary<Type, Func<object>> _registry = new Dictionary<Type, Func<object>>();
private readonly Dictionary<Type, Func<object?>> _registry = new Dictionary<Type, Func<object?>>();
static AvaloniaLocator()
{
@ -27,10 +27,9 @@ namespace Avalonia
_parentScope = parentScope;
}
public object GetService(Type t)
public object? GetService(Type t)
{
Func<object> rv;
return _registry.TryGetValue(t, out rv) ? rv() : _parentScope?.GetService(t);
return _registry.TryGetValue(t, out var rv) ? rv() : _parentScope?.GetService(t);
}
public class RegistrationHelper<TService>
@ -57,7 +56,7 @@ namespace Avalonia
public AvaloniaLocator ToLazy<TImlp>(Func<TImlp> func) where TImlp : TService
{
var constructed = false;
TImlp instance = default;
TImlp? instance = default;
_locator._registry[typeof (TService)] = () =>
{
if (!constructed)
@ -73,7 +72,7 @@ namespace Avalonia
public AvaloniaLocator ToSingleton<TImpl>() where TImpl : class, TService, new()
{
TImpl instance = null;
TImpl? instance = null;
return ToFunc(() => instance ?? (instance = new TImpl()));
}
@ -117,14 +116,14 @@ namespace Avalonia
public interface IAvaloniaDependencyResolver
{
object GetService(Type t);
object? GetService(Type t);
}
public static class LocatorExtensions
{
public static T GetService<T>(this IAvaloniaDependencyResolver resolver)
public static T? GetService<T>(this IAvaloniaDependencyResolver resolver)
{
return (T) resolver.GetService(typeof (T));
return (T?) resolver.GetService(typeof (T));
}
}
}

6
src/Avalonia.Base/AvaloniaObject.cs

@ -7,8 +7,6 @@ using Avalonia.Logging;
using Avalonia.PropertyStore;
using Avalonia.Threading;
#nullable enable
namespace Avalonia
{
/// <summary>
@ -47,7 +45,7 @@ namespace Avalonia
/// <summary>
/// Raised when a <see cref="AvaloniaProperty"/> value changes on this object.
/// </summary>
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged
{
add { _inpcChanged += value; }
remove { _inpcChanged -= value; }
@ -857,7 +855,7 @@ namespace Avalonia
private string GetDescription(object o)
{
var description = o as IDescription;
return description?.Description ?? o.ToString();
return description?.Description ?? o.ToString() ?? o.GetType().Name;
}
/// <summary>

2
src/Avalonia.Base/AvaloniaObjectExtensions.cs

@ -6,8 +6,6 @@ using System.Reactive.Subjects;
using Avalonia.Data;
using Avalonia.Reactive;
#nullable enable
namespace Avalonia
{
/// <summary>

6
src/Avalonia.Base/AvaloniaProperty.cs

@ -4,8 +4,6 @@ using Avalonia.Data;
using Avalonia.Data.Core;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia
{
/// <summary>
@ -544,12 +542,12 @@ namespace Avalonia
throw new ArgumentNullException(nameof(type));
}
if (_metadataCache.TryGetValue(type, out AvaloniaPropertyMetadata result))
if (_metadataCache.TryGetValue(type, out var result))
{
return result;
}
Type currentType = type;
Type? currentType = type;
while (currentType != null)
{

2
src/Avalonia.Base/AvaloniaPropertyChangedEventArgs.cs

@ -1,8 +1,6 @@
using System;
using Avalonia.Data;
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/AvaloniaPropertyChangedEventArgs`1.cs

@ -1,7 +1,5 @@
using Avalonia.Data;
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/AvaloniaPropertyMetadata.cs

@ -1,7 +1,5 @@
using Avalonia.Data;
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/AvaloniaPropertyRegistry.cs

@ -2,8 +2,6 @@ using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
#nullable enable
namespace Avalonia
{
/// <summary>

10
src/Avalonia.Base/AvaloniaProperty`1.cs

@ -3,8 +3,6 @@ using System.Reactive.Subjects;
using Avalonia.Data;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia
{
/// <summary>
@ -84,15 +82,15 @@ namespace Avalonia
protected override IObservable<AvaloniaPropertyChangedEventArgs> GetChanged() => Changed;
protected BindingValue<object> TryConvert(object? value)
protected BindingValue<object?> TryConvert(object? value)
{
if (value == UnsetValue)
{
return BindingValue<object>.Unset;
return BindingValue<object?>.Unset;
}
else if (value == BindingOperations.DoNothing)
{
return BindingValue<object>.DoNothing;
return BindingValue<object?>.DoNothing;
}
if (!TypeUtilities.TryConvertImplicit(PropertyType, value, out var converted))
@ -102,7 +100,7 @@ namespace Avalonia
Name,
value,
value?.GetType().FullName ?? "(null)"));
return BindingValue<object>.BindingError(error);
return BindingValue<object?>.BindingError(error);
}
return converted;

18
src/Avalonia.Base/Collections/AvaloniaDictionary.cs

@ -3,11 +3,10 @@ using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Avalonia.Data.Core;
#nullable enable
namespace Avalonia.Collections
{
/// <summary>
@ -19,6 +18,7 @@ namespace Avalonia.Collections
IDictionary,
INotifyCollectionChanged,
INotifyPropertyChanged
where TKey : notnull
{
private Dictionary<TKey, TValue> _inner;
@ -76,8 +76,7 @@ namespace Avalonia.Collections
set
{
TValue old;
bool replace = _inner.TryGetValue(key, out old);
bool replace = _inner.TryGetValue(key, out var old);
_inner[key] = value;
if (replace)
@ -89,7 +88,7 @@ namespace Avalonia.Collections
var e = new NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction.Replace,
new KeyValuePair<TKey, TValue>(key, value),
new KeyValuePair<TKey, TValue>(key, old));
new KeyValuePair<TKey, TValue>(key, old!));
CollectionChanged(this, e);
}
}
@ -100,7 +99,7 @@ namespace Avalonia.Collections
}
}
object IDictionary.this[object key] { get => ((IDictionary)_inner)[key]; set => ((IDictionary)_inner)[key] = value; }
object? IDictionary.this[object key] { get => ((IDictionary)_inner)[key]; set => ((IDictionary)_inner)[key] = value; }
/// <inheritdoc/>
public void Add(TKey key, TValue value)
@ -145,7 +144,7 @@ namespace Avalonia.Collections
/// <inheritdoc/>
public bool Remove(TKey key)
{
if (_inner.TryGetValue(key, out TValue value))
if (_inner.TryGetValue(key, out var value))
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[{key}]"));
@ -168,8 +167,7 @@ namespace Avalonia.Collections
}
/// <inheritdoc/>
public bool TryGetValue(TKey key, out TValue value) => _inner.TryGetValue(key, out value);
public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) => _inner.TryGetValue(key, out value);
/// <inheritdoc/>
IEnumerator IEnumerable.GetEnumerator() => _inner.GetEnumerator();
@ -195,7 +193,7 @@ namespace Avalonia.Collections
}
/// <inheritdoc/>
void IDictionary.Add(object key, object value) => Add((TKey)key, (TValue)value);
void IDictionary.Add(object key, object? value) => Add((TKey)key, (TValue)value!);
/// <inheritdoc/>
bool IDictionary.Contains(object key) => ((IDictionary) _inner).Contains(key);

6
src/Avalonia.Base/Collections/AvaloniaList.cs

@ -6,8 +6,6 @@ using System.ComponentModel;
using System.Linq;
using Avalonia.Diagnostics;
#nullable enable
namespace Avalonia.Collections
{
/// <summary>
@ -95,7 +93,7 @@ namespace Avalonia.Collections
/// <summary>
/// Raised when a change is made to the collection's items.
/// </summary>
public event NotifyCollectionChangedEventHandler CollectionChanged
public event NotifyCollectionChangedEventHandler? CollectionChanged
{
add => _collectionChanged += value;
remove => _collectionChanged -= value;
@ -135,7 +133,7 @@ namespace Avalonia.Collections
bool ICollection.IsSynchronized => false;
/// <inheritdoc/>
object? ICollection.SyncRoot => null;
object ICollection.SyncRoot => this;
/// <inheritdoc/>
bool ICollection<T>.IsReadOnly => false;

13
src/Avalonia.Base/Collections/AvaloniaListConverter.cs

@ -3,8 +3,6 @@ using System.ComponentModel;
using System.Globalization;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Collections
{
/// <summary>
@ -12,23 +10,26 @@ namespace Avalonia.Collections
/// </summary>
public class AvaloniaListConverter<T> : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
return sourceType == typeof(string);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
{
if (value is not string stringValue)
return null;
var result = new AvaloniaList<T>();
// TODO: Use StringTokenizer here.
var values = ((string)value).Split(',');
var values = stringValue.Split(',');
foreach (var s in values)
{
if (TypeUtilities.TryConvert(typeof(T), s, culture, out var v))
{
result.Add((T)v);
result.Add((T)v!);
}
else
{

16
src/Avalonia.Base/Collections/AvaloniaListExtensions.cs

@ -5,8 +5,6 @@ using System.Collections.Specialized;
using System.ComponentModel;
using System.Reactive.Disposables;
#nullable enable
namespace Avalonia.Collections
{
/// <summary>
@ -88,7 +86,7 @@ namespace Avalonia.Collections
{
for (var i = items.Count - 1; i >= 0; --i)
{
removed(index + i, (T)items[i]);
removed(index + i, (T)items[i]!);
}
}
@ -97,22 +95,22 @@ namespace Avalonia.Collections
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
Add(e.NewStartingIndex, e.NewItems);
Add(e.NewStartingIndex, e.NewItems!);
break;
case NotifyCollectionChangedAction.Move:
case NotifyCollectionChangedAction.Replace:
Remove(e.OldStartingIndex, e.OldItems);
Remove(e.OldStartingIndex, e.OldItems!);
int newIndex = e.NewStartingIndex;
if(newIndex > e.OldStartingIndex)
{
newIndex -= e.OldItems.Count;
newIndex -= e.OldItems!.Count;
}
Add(newIndex, e.NewItems);
Add(newIndex, e.NewItems!);
break;
case NotifyCollectionChangedAction.Remove:
Remove(e.OldStartingIndex, e.OldItems);
Remove(e.OldStartingIndex, e.OldItems!);
break;
case NotifyCollectionChangedAction.Reset:
@ -166,7 +164,7 @@ namespace Avalonia.Collections
/// <returns>A disposable used to terminate the subscription.</returns>
public static IDisposable TrackItemPropertyChanged<T>(
this IAvaloniaReadOnlyList<T> collection,
Action<Tuple<object, PropertyChangedEventArgs>> callback)
Action<Tuple<object?, PropertyChangedEventArgs>> callback)
{
List<INotifyPropertyChanged> tracked = new List<INotifyPropertyChanged>();

2
src/Avalonia.Base/Collections/IAvaloniaList.cs

@ -1,7 +1,5 @@
using System.Collections.Generic;
#nullable enable
namespace Avalonia.Collections
{
/// <summary>

2
src/Avalonia.Base/Collections/IAvaloniaReadOnlyList.cs

@ -2,8 +2,6 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
#nullable enable
namespace Avalonia.Collections
{
/// <summary>

8
src/Avalonia.Base/Collections/NotifyCollectionChangedExtensions.cs

@ -4,8 +4,6 @@ using System.Reactive.Linq;
using Avalonia.Reactive;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Collections
{
public static class NotifyCollectionChangedExtensions
@ -70,14 +68,14 @@ namespace Avalonia.Collections
_sourceReference = source;
}
public void OnEvent(object sender, NotifyCollectionChangedEventArgs e)
public void OnEvent(object? sender, NotifyCollectionChangedEventArgs e)
{
PublishNext(e);
}
protected override void Initialize()
{
if (_sourceReference.TryGetTarget(out INotifyCollectionChanged instance))
if (_sourceReference.TryGetTarget(out var instance))
{
WeakSubscriptionManager.Subscribe(
instance,
@ -88,7 +86,7 @@ namespace Avalonia.Collections
protected override void Deinitialize()
{
if (_sourceReference.TryGetTarget(out INotifyCollectionChanged instance))
if (_sourceReference.TryGetTarget(out var instance))
{
WeakSubscriptionManager.Unsubscribe(
instance,

2
src/Avalonia.Base/Collections/Pooled/ClearMode.cs

@ -1,8 +1,6 @@
// This source file is adapted from the Collections.Pooled.
// (https://github.com/jtmueller/Collections.Pooled/tree/master/Collections.Pooled/)
#nullable enable
namespace Avalonia.Collections.Pooled
{
/// <summary>

2
src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs

@ -6,8 +6,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
#nullable enable
namespace Avalonia.Collections.Pooled
{
internal sealed class ICollectionDebugView<T>

2
src/Avalonia.Base/Collections/Pooled/IReadOnlyPooledList.cs

@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
#nullable enable
namespace Avalonia.Collections.Pooled
{
/// <summary>

17
src/Avalonia.Base/Collections/Pooled/PooledList.cs

@ -13,8 +13,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Threading;
#nullable enable
namespace Avalonia.Collections.Pooled
{
/// <summary>
@ -656,14 +654,15 @@ namespace Avalonia.Collections.Pooled
// compatible array type.
void ICollection.CopyTo(Array array, int arrayIndex)
{
if ((array != null) && (array.Rank != 1))
_ = array ?? throw new ArgumentNullException(nameof(array));
if (array.Rank != 1)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
}
try
{
// Array.Copy will check for NULL.
Array.Copy(_items, 0, array, arrayIndex, _size);
}
catch (ArrayTypeMismatchException)
@ -1336,7 +1335,7 @@ namespace Avalonia.Collections.Pooled
_version++;
}
public void Sort(Func<T, T, int> comparison)
public void Sort(Func<T?, T?, int> comparison)
{
if (comparison == null)
{
@ -1442,7 +1441,7 @@ namespace Avalonia.Collections.Pooled
_version++;
}
void IDeserializationCallback.OnDeserialization(object sender)
void IDeserializationCallback.OnDeserialization(object? sender)
{
// We can't serialize array pools, so deserialized PooledLists will
// have to use the shared pool, even if they were using a custom pool
@ -1522,14 +1521,14 @@ namespace Avalonia.Collections.Pooled
private readonly struct Comparer : IComparer<T>
{
private readonly Func<T, T, int> _comparison;
private readonly Func<T?, T?, int> _comparison;
public Comparer(Func<T, T, int> comparison)
public Comparer(Func<T?, T?, int> comparison)
{
_comparison = comparison;
}
public int Compare(T x, T y) => _comparison(x, y);
public int Compare(T? x, T? y) => _comparison(x, y);
}
}
}

4
src/Avalonia.Base/Collections/Pooled/PooledStack.cs

@ -20,8 +20,6 @@ using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Threading;
#nullable enable
namespace Avalonia.Collections.Pooled
{
/// <summary>
@ -613,7 +611,7 @@ namespace Avalonia.Collections.Pooled
_version++;
}
void IDeserializationCallback.OnDeserialization(object sender)
void IDeserializationCallback.OnDeserialization(object? sender)
{
// We can't serialize array pools, so deserialized PooledStacks will
// have to use the shared pool, even if they were using a custom pool

2
src/Avalonia.Base/Collections/Pooled/StackDebugView.cs

@ -5,8 +5,6 @@
using System;
using System.Diagnostics;
#nullable enable
namespace Avalonia.Collections.Pooled
{
internal sealed class StackDebugView<T>

2
src/Avalonia.Base/Collections/Pooled/ThrowHelper.cs

@ -42,8 +42,6 @@ using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
#nullable enable
namespace Avalonia.Collections.Pooled
{
internal static class ThrowHelper

2
src/Avalonia.Base/Data/AssignBindingAttribute.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data
{
/// <summary>

2
src/Avalonia.Base/Data/BindingChainException.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data
{
/// <summary>

2
src/Avalonia.Base/Data/BindingMode.cs

@ -1,5 +1,3 @@
#nullable enable
namespace Avalonia.Data
{
/// <summary>

8
src/Avalonia.Base/Data/BindingNotification.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data
{
/// <summary>
@ -214,8 +212,10 @@ namespace Avalonia.Data
/// <param name="type">The error type.</param>
public void AddError(Exception e, BindingErrorType type)
{
Contract.Requires<ArgumentNullException>(e != null);
Contract.Requires<ArgumentException>(type != BindingErrorType.None);
_ = e ?? throw new ArgumentNullException(nameof(e));
if (type == BindingErrorType.None)
throw new ArgumentException("BindingErrorType may not be None", nameof(type));
Error = Error != null ? new AggregateException(Error, e) : e;

2
src/Avalonia.Base/Data/BindingOperations.cs

@ -2,8 +2,6 @@ using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
#nullable enable
namespace Avalonia.Data
{
public static class BindingOperations

2
src/Avalonia.Base/Data/BindingPriority.cs

@ -1,5 +1,3 @@
#nullable enable
namespace Avalonia.Data
{
/// <summary>

8
src/Avalonia.Base/Data/BindingValue.cs

@ -2,8 +2,6 @@
using System.Diagnostics;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Data
{
/// <summary>
@ -418,15 +416,15 @@ namespace Avalonia.Data
{
BindingValueType.DoNothing => BindingValue<T>.DoNothing,
BindingValueType.UnsetValue => BindingValue<T>.Unset,
BindingValueType.Value => new BindingValue<T>(TypeUtilities.ConvertImplicit<T>(value.Value)),
BindingValueType.Value => new BindingValue<T>(TypeUtilities.ConvertImplicit<T>(value.Value!)),
BindingValueType.BindingError => BindingValue<T>.BindingError(value.Error!),
BindingValueType.BindingErrorWithFallback => BindingValue<T>.BindingError(
value.Error!,
TypeUtilities.ConvertImplicit<T>(value.Value)),
TypeUtilities.ConvertImplicit<T>(value.Value!)),
BindingValueType.DataValidationError => BindingValue<T>.DataValidationError(value.Error!),
BindingValueType.DataValidationErrorWithFallback => BindingValue<T>.DataValidationError(
value.Error!,
TypeUtilities.ConvertImplicit<T>(value.Value)),
TypeUtilities.ConvertImplicit<T>(value.Value!)),
_ => throw new NotSupportedException("Invalid BindingValue type."),
};
}

2
src/Avalonia.Base/Data/Converters/BoolConverters.cs

@ -1,7 +1,5 @@
using System.Linq;
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>

4
src/Avalonia.Base/Data/Converters/DefaultValueConverter.cs

@ -3,8 +3,6 @@ using System.Globalization;
using System.Windows.Input;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>
@ -38,7 +36,7 @@ namespace Avalonia.Data.Converters
return new MethodToCommandConverter(d);
}
if (TypeUtilities.TryConvert(targetType, value, culture, out object result))
if (TypeUtilities.TryConvert(targetType, value, culture, out var result))
{
return result;
}

2
src/Avalonia.Base/Data/Converters/FuncMultiValueConverter.cs

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>

2
src/Avalonia.Base/Data/Converters/FuncValueConverter.cs

@ -2,8 +2,6 @@ using System;
using System.Globalization;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>

2
src/Avalonia.Base/Data/Converters/IMultiValueConverter.cs

@ -2,8 +2,6 @@ using System;
using System.Collections.Generic;
using System.Globalization;
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>

2
src/Avalonia.Base/Data/Converters/IValueConverter.cs

@ -1,8 +1,6 @@
using System;
using System.Globalization;
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>

38
src/Avalonia.Base/Data/Converters/MethodToCommandConverter.cs

@ -7,19 +7,17 @@ using System.Reflection;
using System.Windows.Input;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Data.Converters
{
class MethodToCommandConverter : ICommand
{
readonly static Func<object, bool> AlwaysEnabled = (_) => true;
readonly static Func<object?, bool> AlwaysEnabled = (_) => true;
readonly static MethodInfo tryConvert = typeof(TypeUtilities)
.GetMethod(nameof(TypeUtilities.TryConvert), BindingFlags.Public | BindingFlags.Static);
.GetMethod(nameof(TypeUtilities.TryConvert), BindingFlags.Public | BindingFlags.Static)!;
readonly static PropertyInfo currentCulture = typeof(CultureInfo)
.GetProperty(nameof(CultureInfo.CurrentCulture), BindingFlags.Public | BindingFlags.Static);
readonly Func<object, bool> canExecute;
readonly Action<object> execute;
.GetProperty(nameof(CultureInfo.CurrentCulture), BindingFlags.Public | BindingFlags.Static)!;
readonly Func<object?, bool> canExecute;
readonly Action<object?> execute;
readonly WeakPropertyChangedProxy? weakPropertyChanged;
readonly PropertyChangedEventHandler? propertyChangedEventHandler;
readonly string[]? dependencyProperties;
@ -40,7 +38,7 @@ namespace Avalonia.Data.Converters
execute = CreateExecute(target, action.Method, parameterInfo);
}
var canExecuteMethod = action.Method.DeclaringType.GetRuntimeMethods()
var canExecuteMethod = action.Method.DeclaringType?.GetRuntimeMethods()
.FirstOrDefault(m => m.Name == canExecuteMethodName
&& m.GetParameters().Length == 1
&& m.GetParameters()[0].ParameterType == typeof(object));
@ -65,7 +63,7 @@ namespace Avalonia.Data.Converters
}
}
void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
void OnPropertyChanged(object? sender, PropertyChangedEventArgs args)
{
if (string.IsNullOrWhiteSpace(args.PropertyName)
|| dependencyProperties?.Contains(args.PropertyName) == true)
@ -79,12 +77,12 @@ namespace Avalonia.Data.Converters
public event EventHandler? CanExecuteChanged;
#pragma warning restore 0067
public bool CanExecute(object parameter) => canExecute(parameter);
public bool CanExecute(object? parameter) => canExecute(parameter);
public void Execute(object parameter) => execute(parameter);
public void Execute(object? parameter) => execute(parameter);
static Action<object> CreateExecute(object target
static Action<object?> CreateExecute(object? target
, System.Reflection.MethodInfo method)
{
@ -100,11 +98,11 @@ namespace Avalonia.Data.Converters
return Expression
.Lambda<Action<object>>(call, parameter)
.Lambda<Action<object?>>(call, parameter)
.Compile();
}
static Action<object> CreateExecute(object target
static Action<object?> CreateExecute(object? target
, System.Reflection.MethodInfo method
, Type parameterType)
{
@ -143,11 +141,11 @@ namespace Avalonia.Data.Converters
}
return Expression
.Lambda<Action<object>>(body, parameter)
.Lambda<Action<object?>>(body, parameter)
.Compile();
}
static Func<object, bool> CreateCanExecute(object target
static Func<object?, bool> CreateCanExecute(object? target
, System.Reflection.MethodInfo method)
{
var parameter = Expression.Parameter(typeof(object), "parameter");
@ -159,12 +157,12 @@ namespace Avalonia.Data.Converters
parameter
);
return Expression
.Lambda<Func<object, bool>>(call, parameter)
.Lambda<Func<object?, bool>>(call, parameter)
.Compile();
}
private static Expression? ConvertTarget(object target, MethodInfo method) =>
target is null ? null : Expression.Convert(Expression.Constant(target), method.DeclaringType);
private static Expression? ConvertTarget(object? target, MethodInfo method) =>
target is null ? null : Expression.Convert(Expression.Constant(target), method.DeclaringType!);
internal class WeakPropertyChangedProxy
{
@ -199,7 +197,7 @@ namespace Avalonia.Data.Converters
_listener.SetTarget(null);
}
void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (_listener.TryGetTarget(out var handler) && handler != null)
handler(sender, e);

2
src/Avalonia.Base/Data/Converters/ObjectConverters.cs

@ -1,5 +1,3 @@
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>

2
src/Avalonia.Base/Data/Converters/StringConverters.cs

@ -1,5 +1,3 @@
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>

2
src/Avalonia.Base/Data/Converters/StringFormatMultiValueConverter.cs

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>

2
src/Avalonia.Base/Data/Converters/StringFormatValueConverter.cs

@ -1,8 +1,6 @@
using System;
using System.Globalization;
#nullable enable
namespace Avalonia.Data.Converters
{
/// <summary>

2
src/Avalonia.Base/Data/Core/AvaloniaPropertyAccessorNode.cs

@ -2,8 +2,6 @@
using System.Reactive.Linq;
using Avalonia.Reactive;
#nullable enable
namespace Avalonia.Data.Core
{
public class AvaloniaPropertyAccessorNode : SettableNode

4
src/Avalonia.Base/Data/Core/BindingExpression.cs

@ -7,8 +7,6 @@ using Avalonia.Logging;
using Avalonia.Reactive;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Data.Core
{
/// <summary>
@ -263,7 +261,7 @@ namespace Avalonia.Data.Core
private BindingNotification ConvertFallback()
{
object converted;
object? converted;
if (_fallbackValue == AvaloniaProperty.UnsetValue)
{

6
src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs

@ -2,8 +2,6 @@ using System;
using System.Linq.Expressions;
using System.Reflection;
#nullable enable
namespace Avalonia.Data.Core
{
public class ClrPropertyInfo : IPropertyInfo
@ -49,7 +47,7 @@ namespace Avalonia.Data.Core
var target = Expression.Parameter(typeof(object), "target");
var value = Expression.Parameter(typeof(object), "value");
return Expression.Lambda<Action<object, object?>>(
Expression.Call(Expression.Convert(target, info.DeclaringType), info.SetMethod,
Expression.Call(Expression.Convert(target, info.DeclaringType!), info.SetMethod,
Expression.Convert(value, info.SetMethod.GetParameters()[0].ParameterType)),
target, value)
.Compile();
@ -61,7 +59,7 @@ namespace Avalonia.Data.Core
return null;
var target = Expression.Parameter(typeof(object), "target");
return Expression.Lambda<Func<object, object>>(
Expression.Convert(Expression.Call(Expression.Convert(target, info.DeclaringType), info.GetMethod),
Expression.Convert(Expression.Call(Expression.Convert(target, info.DeclaringType!), info.GetMethod),
typeof(object)))
.Compile();
}

2
src/Avalonia.Base/Data/Core/CommonPropertyNames.cs

@ -1,5 +1,3 @@
#nullable enable
namespace Avalonia.Data.Core
{
public static class CommonPropertyNames

4
src/Avalonia.Base/Data/Core/EmptyExpressionNode.cs

@ -1,6 +1,4 @@
#nullable enable
namespace Avalonia.Data.Core
namespace Avalonia.Data.Core
{
public class EmptyExpressionNode : ExpressionNode
{

2
src/Avalonia.Base/Data/Core/ExpressionNode.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core
{
public abstract class ExpressionNode

2
src/Avalonia.Base/Data/Core/ExpressionObserver.cs

@ -7,8 +7,6 @@ using Avalonia.Data.Core.Parsers;
using Avalonia.Data.Core.Plugins;
using Avalonia.Reactive;
#nullable enable
namespace Avalonia.Data.Core
{
/// <summary>

2
src/Avalonia.Base/Data/Core/ExpressionParseException.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core
{
/// <summary>

2
src/Avalonia.Base/Data/Core/IPropertyInfo.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core
{
public interface IPropertyInfo

4
src/Avalonia.Base/Data/Core/ITransformNode.cs

@ -1,6 +1,4 @@
#nullable enable
namespace Avalonia.Data.Core
namespace Avalonia.Data.Core
{
interface ITransformNode
{

4
src/Avalonia.Base/Data/Core/IndexerExpressionNode.cs

@ -4,8 +4,6 @@ using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;
#nullable enable
namespace Avalonia.Data.Core
{
class IndexerExpressionNode : IndexerNodeBase
@ -18,7 +16,7 @@ namespace Avalonia.Data.Core
public IndexerExpressionNode(IndexExpression expression)
{
_parameter = Expression.Parameter(expression.Object.Type);
_parameter = Expression.Parameter(expression.Object!.Type);
_expression = expression.Update(_parameter, expression.Arguments);
_getDelegate = Expression.Lambda(_expression, _parameter).Compile();

8
src/Avalonia.Base/Data/Core/IndexerNodeBase.cs

@ -7,8 +7,6 @@ using System.Linq;
using System.Reactive.Linq;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Data.Core
{
public abstract class IndexerNodeBase : SettableNode
@ -72,12 +70,12 @@ namespace Avalonia.Data.Core
return index >= e.OldStartingIndex;
case NotifyCollectionChangedAction.Replace:
return index >= e.NewStartingIndex &&
index < e.NewStartingIndex + e.NewItems.Count;
index < e.NewStartingIndex + e.NewItems!.Count;
case NotifyCollectionChangedAction.Move:
return (index >= e.NewStartingIndex &&
index < e.NewStartingIndex + e.NewItems.Count) ||
index < e.NewStartingIndex + e.NewItems!.Count) ||
(index >= e.OldStartingIndex &&
index < e.OldStartingIndex + e.OldItems.Count);
index < e.OldStartingIndex + e.OldItems!.Count);
case NotifyCollectionChangedAction.Reset:
return true;
}

2
src/Avalonia.Base/Data/Core/LogicalNotNode.cs

@ -1,8 +1,6 @@
using System;
using System.Globalization;
#nullable enable
namespace Avalonia.Data.Core
{
public class LogicalNotNode : ExpressionNode, ITransformNode

2
src/Avalonia.Base/Data/Core/MarkupBindingChainException.cs

@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Linq;
#nullable enable
namespace Avalonia.Data.Core
{
internal class MarkupBindingChainException : BindingChainException

2
src/Avalonia.Base/Data/Core/Parsers/ExpressionTreeParser.cs

@ -1,8 +1,6 @@
using System.Linq;
using System.Linq.Expressions;
#nullable enable
namespace Avalonia.Data.Core.Parsers
{
static class ExpressionTreeParser

18
src/Avalonia.Base/Data/Core/Parsers/ExpressionVisitorNodeBuilder.cs

@ -4,8 +4,6 @@ using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
#nullable enable
namespace Avalonia.Data.Core.Parsers
{
class ExpressionVisitorNodeBuilder : ExpressionVisitor
@ -18,8 +16,8 @@ namespace Avalonia.Data.Core.Parsers
static ExpressionVisitorNodeBuilder()
{
AvaloniaObjectIndexer = typeof(AvaloniaObject).GetProperty("Item", new[] { typeof(AvaloniaProperty) });
CreateDelegateMethod = typeof(MethodInfo).GetMethod("CreateDelegate", new[] { typeof(Type), typeof(object) });
AvaloniaObjectIndexer = typeof(AvaloniaObject).GetProperty("Item", new[] { typeof(AvaloniaProperty) })!;
CreateDelegateMethod = typeof(MethodInfo).GetMethod("CreateDelegate", new[] { typeof(Type), typeof(object) })!;
}
public List<ExpressionNode> Nodes { get; }
@ -164,7 +162,7 @@ namespace Avalonia.Data.Core.Parsers
if (node.Method == CreateDelegateMethod)
{
var visited = Visit(node.Arguments[1]);
Nodes.Add(new PropertyAccessorNode(GetArgumentExpressionValue<MethodInfo>(node.Object).Name, _enableDataValidation));
Nodes.Add(new PropertyAccessorNode(GetArgumentExpressionValue<MethodInfo>(node.Object!).Name, _enableDataValidation));
return node;
}
else if (node.Method.Name == StreamBindingExtensions.StreamBindingName || node.Method.Name.StartsWith(StreamBindingExtensions.StreamBindingName + '`'))
@ -185,20 +183,20 @@ namespace Avalonia.Data.Core.Parsers
if (property != null)
{
return Visit(Expression.MakeIndex(node.Object, property, node.Arguments));
return Visit(Expression.MakeIndex(node.Object!, property, node.Arguments));
}
else if (node.Object.Type.IsArray && node.Method.Name == MultiDimensionalArrayGetterMethodName)
else if (node.Object!.Type.IsArray && node.Method.Name == MultiDimensionalArrayGetterMethodName)
{
return Visit(Expression.MakeIndex(node.Object, null, node.Arguments));
}
throw new ExpressionParseException(0, $"Invalid method call in binding expression: '{node.Method.DeclaringType.AssemblyQualifiedName}.{node.Method.Name}'.");
throw new ExpressionParseException(0, $"Invalid method call in binding expression: '{node.Method.DeclaringType!.AssemblyQualifiedName}.{node.Method.Name}'.");
}
private PropertyInfo TryGetPropertyFromMethod(MethodInfo method)
private PropertyInfo? TryGetPropertyFromMethod(MethodInfo method)
{
var type = method.DeclaringType;
return type.GetRuntimeProperties().FirstOrDefault(prop => prop.GetMethod == method);
return type?.GetRuntimeProperties().FirstOrDefault(prop => prop.GetMethod == method);
}
protected override Expression VisitSwitch(SwitchExpression node)

9
src/Avalonia.Base/Data/Core/Plugins/AvaloniaPropertyAccessorPlugin.cs

@ -1,8 +1,6 @@
using System;
using System.Runtime.ExceptionServices;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>
@ -74,12 +72,11 @@ namespace Avalonia.Data.Core.Plugins
_property = property ?? throw new ArgumentNullException(nameof(property));
}
public AvaloniaObject Instance
public AvaloniaObject? Instance
{
get
{
AvaloniaObject result;
_reference.TryGetTarget(out result);
_reference.TryGetTarget(out var result);
return result;
}
}
@ -91,7 +88,7 @@ namespace Avalonia.Data.Core.Plugins
{
if (!_property.IsReadOnly)
{
Instance.SetValue(_property, value, priority);
Instance?.SetValue(_property, value, priority);
return true;
}

16
src/Avalonia.Base/Data/Core/Plugins/DataAnnotationsValidationPlugin.cs

@ -4,8 +4,6 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>
@ -33,19 +31,23 @@ namespace Avalonia.Data.Core.Plugins
private sealed class Accessor : DataValidationBase
{
private readonly ValidationContext _context;
private readonly ValidationContext? _context;
public Accessor(WeakReference<object?> reference, string name, IPropertyAccessor inner)
: base(inner)
{
reference.TryGetTarget(out var target);
_context = new ValidationContext(target);
_context.MemberName = name;
if (reference.TryGetTarget(out var target))
{
_context = new ValidationContext(target);
_context.MemberName = name;
}
}
protected override void InnerValueChanged(object? value)
{
if (_context is null)
return;
var errors = new List<ValidationResult>();
if (Validator.TryValidateProperty(value, _context, errors))

2
src/Avalonia.Base/Data/Core/Plugins/DataValidationBase.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>

4
src/Avalonia.Base/Data/Core/Plugins/ExceptionValidationPlugin.cs

@ -1,8 +1,6 @@
using System;
using System.Reflection;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>
@ -32,7 +30,7 @@ namespace Avalonia.Data.Core.Plugins
{
return base.SetValue(value, priority);
}
catch (TargetInvocationException ex)
catch (TargetInvocationException ex) when (ex.InnerException is not null)
{
PublishValue(new BindingNotification(ex.InnerException, BindingErrorType.DataValidationError));
}

2
src/Avalonia.Base/Data/Core/Plugins/IDataValidationPlugin.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>

2
src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessor.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>

2
src/Avalonia.Base/Data/Core/Plugins/IPropertyAccessorPlugin.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>

2
src/Avalonia.Base/Data/Core/Plugins/IStreamPlugin.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>

4
src/Avalonia.Base/Data/Core/Plugins/IndeiValidationPlugin.cs

@ -4,8 +4,6 @@ using System.ComponentModel;
using System.Linq;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>
@ -39,7 +37,7 @@ namespace Avalonia.Data.Core.Plugins
_name = name;
}
void IWeakSubscriber<DataErrorsChangedEventArgs>.OnEvent(object sender, DataErrorsChangedEventArgs e)
void IWeakSubscriber<DataErrorsChangedEventArgs>.OnEvent(object? sender, DataErrorsChangedEventArgs e)
{
if (e.PropertyName == _name || string.IsNullOrEmpty(e.PropertyName))
{

4
src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs

@ -4,8 +4,6 @@ using System.ComponentModel;
using System.Reflection;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>
@ -131,7 +129,7 @@ namespace Avalonia.Data.Core.Plugins
return false;
}
void IWeakSubscriber<PropertyChangedEventArgs>.OnEvent(object sender, PropertyChangedEventArgs e)
void IWeakSubscriber<PropertyChangedEventArgs>.OnEvent(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == _property.Name || string.IsNullOrEmpty(e.PropertyName))
{

2
src/Avalonia.Base/Data/Core/Plugins/MethodAccessorPlugin.cs

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
public class MethodAccessorPlugin : IPropertyAccessorPlugin

8
src/Avalonia.Base/Data/Core/Plugins/ObservableStreamPlugin.cs

@ -3,8 +3,6 @@ using System.Linq;
using System.Reactive.Linq;
using System.Reflection;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>
@ -57,14 +55,14 @@ namespace Avalonia.Data.Core.Plugins
// Make a Box<> delegate of the correct type.
var funcType = typeof(Func<,>).MakeGenericType(sourceType, typeof(object));
var box = GetType().GetMethod(nameof(Box), BindingFlags.Static | BindingFlags.NonPublic)
var box = GetType().GetMethod(nameof(Box), BindingFlags.Static | BindingFlags.NonPublic)!
.MakeGenericMethod(sourceType)
.CreateDelegate(funcType);
// Call Observable.Select(target, box);
return (IObservable<object>)select.Invoke(
return (IObservable<object?>)select.Invoke(
null,
new object[] { target, box });
new object[] { target, box })!;
}
private static MethodInfo GetObservableSelect(Type source)

2
src/Avalonia.Base/Data/Core/Plugins/PropertyAccessorBase.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>

2
src/Avalonia.Base/Data/Core/Plugins/PropertyError.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>

4
src/Avalonia.Base/Data/Core/Plugins/TaskStreamPlugin.cs

@ -4,8 +4,6 @@ using System.Reactive.Subjects;
using System.Reflection;
using System.Threading.Tasks;
#nullable enable
namespace Avalonia.Data.Core.Plugins
{
/// <summary>
@ -72,7 +70,7 @@ namespace Avalonia.Data.Core.Plugins
case TaskStatus.RanToCompletion:
return Observable.Return(resultProperty.GetValue(task));
case TaskStatus.Faulted:
return Observable.Return(new BindingNotification(task.Exception, BindingErrorType.Error));
return Observable.Return(new BindingNotification(task.Exception!, BindingErrorType.Error));
default:
throw new AvaloniaInternalException("HandleCompleted called for non-completed Task.");
}

2
src/Avalonia.Base/Data/Core/PropertyAccessorNode.cs

@ -2,8 +2,6 @@ using System;
using System.Diagnostics;
using Avalonia.Data.Core.Plugins;
#nullable enable
namespace Avalonia.Data.Core
{
public class PropertyAccessorNode : SettableNode

2
src/Avalonia.Base/Data/Core/PropertyPath.cs

@ -2,8 +2,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
#nullable enable
namespace Avalonia.Data.Core
{
public class PropertyPath

2
src/Avalonia.Base/Data/Core/SettableNode.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data.Core
{
public abstract class SettableNode : ExpressionNode

2
src/Avalonia.Base/Data/Core/StreamBindingExtensions.cs

@ -1,8 +1,6 @@
using System;
using System.Threading.Tasks;
#nullable enable
namespace Avalonia
{
public static class StreamBindingExtensions

2
src/Avalonia.Base/Data/Core/StreamNode.cs

@ -2,8 +2,6 @@ using System;
using System.Reactive.Linq;
using Avalonia.Data.Core.Plugins;
#nullable enable
namespace Avalonia.Data.Core
{
public class StreamNode : ExpressionNode

2
src/Avalonia.Base/Data/Core/TypeCastNode.cs

@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Text;
#nullable enable
namespace Avalonia.Data.Core
{
public class TypeCastNode : ExpressionNode

2
src/Avalonia.Base/Data/DataValidationException.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Data
{
/// <summary>

2
src/Avalonia.Base/Data/IBinding.cs

@ -1,5 +1,3 @@
#nullable enable
namespace Avalonia.Data
{
/// <summary>

4
src/Avalonia.Base/Data/IndexerBinding.cs

@ -1,6 +1,4 @@
#nullable enable
namespace Avalonia.Data
namespace Avalonia.Data
{
public class IndexerBinding : IBinding
{

2
src/Avalonia.Base/Data/IndexerDescriptor.cs

@ -1,8 +1,6 @@
using System;
using System.Reactive;
#nullable enable
namespace Avalonia.Data
{
/// <summary>

2
src/Avalonia.Base/Data/InstancedBinding.cs

@ -1,8 +1,6 @@
using System;
using System.Reactive.Subjects;
#nullable enable
namespace Avalonia.Data
{
/// <summary>

2
src/Avalonia.Base/Data/Optional.cs

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
#nullable enable
namespace Avalonia.Data
{
/// <summary>

8
src/Avalonia.Base/Diagnostics/AvaloniaPropertyValue.cs

@ -17,9 +17,9 @@ namespace Avalonia.Diagnostics
/// <param name="diagnostic">A diagnostic string.</param>
public AvaloniaPropertyValue(
AvaloniaProperty property,
object value,
object? value,
BindingPriority priority,
string diagnostic)
string? diagnostic)
{
Property = property;
Value = value;
@ -35,7 +35,7 @@ namespace Avalonia.Diagnostics
/// <summary>
/// Gets the current property value.
/// </summary>
public object Value { get; }
public object? Value { get; }
/// <summary>
/// Gets the priority of the current value.
@ -45,6 +45,6 @@ namespace Avalonia.Diagnostics
/// <summary>
/// Gets a diagnostic string.
/// </summary>
public string Diagnostic { get; }
public string? Diagnostic { get; }
}
}

2
src/Avalonia.Base/Diagnostics/IAvaloniaObjectDebug.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia.Diagnostics
{
/// <summary>

2
src/Avalonia.Base/Diagnostics/INotifyCollectionChangedDebug.cs

@ -17,6 +17,6 @@ namespace Avalonia.Diagnostics
/// <returns>
/// The subscribers or null if no subscribers.
/// </returns>
Delegate[] GetCollectionChangedSubscribers();
Delegate[]? GetCollectionChangedSubscribers();
}
}

2
src/Avalonia.Base/DirectProperty.cs

@ -2,8 +2,6 @@ using System;
using System.Diagnostics.CodeAnalysis;
using Avalonia.Data;
#nullable enable
namespace Avalonia
{
/// <summary>

4
src/Avalonia.Base/DirectPropertyBase.cs

@ -3,8 +3,6 @@ using Avalonia.Data;
using Avalonia.Reactive;
using Avalonia.Utilities;
#nullable enable
namespace Avalonia
{
/// <summary>
@ -155,7 +153,7 @@ namespace Avalonia
if (v.HasValue)
{
o.SetValue<TValue>(this, (TValue)v.Value);
o.SetValue<TValue>(this, (TValue)v.Value!);
}
else if (v.Type == BindingValueType.UnsetValue)
{

2
src/Avalonia.Base/DirectPropertyMetadata`1.cs

@ -1,7 +1,5 @@
using Avalonia.Data;
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/EnumExtensions.cs

@ -1,8 +1,6 @@
using System;
using System.Runtime.CompilerServices;
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/IAvaloniaObject.cs

@ -1,8 +1,6 @@
using System;
using Avalonia.Data;
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/IDescription.cs

@ -1,5 +1,3 @@
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/IDirectPropertyAccessor.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/IDirectPropertyMetadata.cs

@ -1,5 +1,3 @@
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/IStyledPropertyAccessor.cs

@ -1,7 +1,5 @@
using System;
#nullable enable
namespace Avalonia
{
/// <summary>

2
src/Avalonia.Base/IStyledPropertyMetadata.cs

@ -1,5 +1,3 @@
#nullable enable
namespace Avalonia
{
/// <summary>

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save