Browse Source

More null checks

pull/995/head
Nikita Tsukanov 9 years ago
parent
commit
0b756d0b8a
  1. 1
      Avalonia.sln.DotSettings
  2. 11
      src/Avalonia.Base/AvaloniaObject.cs
  3. 25
      src/Avalonia.Base/Collections/AvaloniaDictionary.cs
  4. 2
      src/Avalonia.Base/PriorityValue.cs
  5. 2
      src/Avalonia.Controls/Button.cs
  6. 2
      src/Avalonia.Controls/Control.cs
  7. 2
      src/Avalonia.Controls/ItemsControl.cs
  8. 7
      src/Avalonia.Controls/TextBox.cs
  9. 2
      src/Avalonia.Controls/TopLevel.cs
  10. 8
      src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs
  11. 2
      src/Avalonia.Styling/Controls/NameScope.cs
  12. 2
      src/Avalonia.Visuals/Rendering/ZIndexComparer.cs
  13. 1
      src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs
  14. 1
      src/Gtk/Avalonia.Gtk3/SystemDialogs.cs
  15. 2
      src/Markup/Avalonia.Markup.Xaml/Parsers/SelectorParser.cs

1
Avalonia.sln.DotSettings

@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=3E53A01A_002DB331_002D47F3_002DB828_002D4A5717E77A24_002Fd_003Aglass/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=6417B24E_002D49C2_002D4985_002D8DB2_002D3AB9D898EC91/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=E3A1060B_002D50D0_002D44E8_002D88B6_002DF44EF2E5BD72_002Ff_003Ahtml_002Ehtm/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantUsingDirective/@EntryIndexedValue">HINT</s:String>

11
src/Avalonia.Base/AvaloniaObject.cs

@ -622,14 +622,9 @@ namespace Avalonia
/// <returns>The default value.</returns>
private object GetDefaultValue(AvaloniaProperty property)
{
if (property.Inherits && _inheritanceParent != null)
{
return (_inheritanceParent as AvaloniaObject).GetValueInternal(property);
}
else
{
return ((IStyledPropertyAccessor)property).GetDefaultValue(GetType());
}
if (property.Inherits && _inheritanceParent is AvaloniaObject aobj)
return aobj.GetValueInternal(property);
return ((IStyledPropertyAccessor) property).GetDefaultValue(GetType());
}
/// <summary>

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

@ -103,11 +103,9 @@ namespace Avalonia.Collections
_inner = new Dictionary<TKey, TValue>();
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Count"));
PropertyChanged(this, new PropertyChangedEventArgs($"Item[]"));
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Count"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[]"));
if (CollectionChanged != null)
{
@ -144,12 +142,9 @@ namespace Avalonia.Collections
if (_inner.TryGetValue(key, out value))
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Count"));
PropertyChanged(this, new PropertyChangedEventArgs($"Item[{key}]"));
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Count"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[{key}]"));
if (CollectionChanged != null)
{
var e = new NotifyCollectionChangedEventArgs(
@ -199,11 +194,9 @@ namespace Avalonia.Collections
private void NotifyAdd(TKey key, TValue value)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Count"));
PropertyChanged(this, new PropertyChangedEventArgs($"Item[{key}]"));
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Count"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[{key}]"));
if (CollectionChanged != null)
{

2
src/Avalonia.Base/PriorityValue.cs

@ -285,7 +285,7 @@ namespace Avalonia
Property.Name,
_valueType,
value,
value.GetType());
value?.GetType());
}
}
}

2
src/Avalonia.Controls/Button.cs

@ -275,7 +275,7 @@ namespace Avalonia.Controls
{
var button = e.Sender as Button;
var isDefault = (bool)e.NewValue;
var inputRoot = button.VisualRoot as IInputElement;
var inputRoot = button?.VisualRoot as IInputElement;
if (inputRoot != null)
{

2
src/Avalonia.Controls/Control.cs

@ -645,7 +645,7 @@ namespace Avalonia.Controls
if (_focusAdorner != null)
{
var adornerLayer = _focusAdorner.Parent as Panel;
var adornerLayer = (Panel)_focusAdorner.Parent;
adornerLayer.Children.Remove(_focusAdorner);
_focusAdorner = null;
}

2
src/Avalonia.Controls/ItemsControl.cs

@ -354,7 +354,7 @@ namespace Avalonia.Controls
}
var collection = sender as ICollection;
PseudoClasses.Set(":empty", collection.Count == 0);
PseudoClasses.Set(":empty", collection == null || collection.Count == 0);
}
/// <summary>

7
src/Avalonia.Controls/TextBox.cs

@ -720,7 +720,7 @@ namespace Avalonia.Controls
if (pos < text.Length)
{
--pos;
if (pos > 0 && Text[pos - 1] == '\r' && Text[pos] == '\n')
if (pos > 0 && text[pos - 1] == '\r' && text[pos] == '\n')
{
--pos;
}
@ -771,6 +771,9 @@ namespace Avalonia.Controls
private string GetSelection()
{
var text = Text;
if (string.IsNullOrEmpty(text))
return "";
var selectionStart = SelectionStart;
var selectionEnd = SelectionEnd;
var start = Math.Min(selectionStart, selectionEnd);
@ -779,7 +782,7 @@ namespace Avalonia.Controls
{
return "";
}
return Text.Substring(start, end - start);
return text.Substring(start, end - start);
}
private int GetLine(int caretIndex, IList<FormattedTextLine> lines)

2
src/Avalonia.Controls/TopLevel.cs

@ -106,7 +106,7 @@ namespace Avalonia.Controls
_accessKeyHandler?.SetOwner(this);
styler?.ApplyStyles(this);
ClientSize = PlatformImpl.ClientSize;
ClientSize = impl.ClientSize;
this.GetObservable(PointerOverElementProperty)
.Select(

8
src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs

@ -82,7 +82,13 @@ namespace Avalonia
private void LoadAssembliesInDirectory()
{
foreach (var file in new FileInfo(Assembly.GetEntryAssembly().Location).Directory.EnumerateFiles("*.dll"))
var location = Assembly.GetEntryAssembly().Location;
if(location == null)
return;
var dir = new FileInfo(location).Directory;
if (dir == null)
return;
foreach (var file in dir.EnumerateFiles("*.dll"))
{
try
{

2
src/Avalonia.Styling/Controls/NameScope.cs

@ -50,7 +50,7 @@ namespace Avalonia.Controls
return result;
}
visual = (visual as ILogical).LogicalParent as Visual;
visual = (visual as ILogical)?.LogicalParent as Visual;
}
return null;

2
src/Avalonia.Visuals/Rendering/ZIndexComparer.cs

@ -8,6 +8,6 @@ namespace Avalonia.Rendering
{
public static readonly ZIndexComparer Instance = new ZIndexComparer();
public int Compare(IVisual x, IVisual y) => x.ZIndex.CompareTo(y.ZIndex);
public int Compare(IVisual x, IVisual y) => (x?.ZIndex ?? 0).CompareTo(y?.ZIndex ?? 0);
}
}

1
src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs

@ -9,6 +9,7 @@ using Avalonia.Cairo.Media.Imaging;
using Avalonia.Media;
using Avalonia.Platform;
using Avalonia.Rendering;
// ReSharper disable PossibleNullReferenceException
namespace Avalonia.Cairo.Media
{

1
src/Gtk/Avalonia.Gtk3/SystemDialogs.cs

@ -28,6 +28,7 @@ namespace Avalonia.Gtk3
List<IDisposable> disposables = null;
Action dispose = () =>
{
// ReSharper disable once PossibleNullReferenceException
foreach (var d in disposables)
d.Dispose();
disposables.Clear();

2
src/Markup/Avalonia.Markup.Xaml/Parsers/SelectorParser.cs

@ -68,7 +68,7 @@ namespace Avalonia.Markup.Xaml.Parsers
}
else if (property != null)
{
var type = result.TargetType;
var type = result?.TargetType;
if (type == null)
{

Loading…
Cancel
Save