Browse Source

More null checks

pull/995/head
Nikita Tsukanov 10 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"> <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/=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/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> <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> /// <returns>The default value.</returns>
private object GetDefaultValue(AvaloniaProperty property) private object GetDefaultValue(AvaloniaProperty property)
{ {
if (property.Inherits && _inheritanceParent != null) if (property.Inherits && _inheritanceParent is AvaloniaObject aobj)
{ return aobj.GetValueInternal(property);
return (_inheritanceParent as AvaloniaObject).GetValueInternal(property); return ((IStyledPropertyAccessor) property).GetDefaultValue(GetType());
}
else
{
return ((IStyledPropertyAccessor)property).GetDefaultValue(GetType());
}
} }
/// <summary> /// <summary>

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

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

2
src/Avalonia.Base/PriorityValue.cs

@ -285,7 +285,7 @@ namespace Avalonia
Property.Name, Property.Name,
_valueType, _valueType,
value, 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 button = e.Sender as Button;
var isDefault = (bool)e.NewValue; var isDefault = (bool)e.NewValue;
var inputRoot = button.VisualRoot as IInputElement; var inputRoot = button?.VisualRoot as IInputElement;
if (inputRoot != null) if (inputRoot != null)
{ {

2
src/Avalonia.Controls/Control.cs

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

2
src/Avalonia.Controls/ItemsControl.cs

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

7
src/Avalonia.Controls/TextBox.cs

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

2
src/Avalonia.Controls/TopLevel.cs

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

8
src/Avalonia.DotNetFrameworkRuntime/AppBuilder.cs

@ -82,7 +82,13 @@ namespace Avalonia
private void LoadAssembliesInDirectory() 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 try
{ {

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

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

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

@ -8,6 +8,6 @@ namespace Avalonia.Rendering
{ {
public static readonly ZIndexComparer Instance = new ZIndexComparer(); 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.Media;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Rendering; using Avalonia.Rendering;
// ReSharper disable PossibleNullReferenceException
namespace Avalonia.Cairo.Media namespace Avalonia.Cairo.Media
{ {

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

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

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

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

Loading…
Cancel
Save