Browse Source

Remove TypeInfo usage in Avalonia.Styling. Avoid pointless type checks.

pull/3486/head
Dariusz Komosinski 6 years ago
parent
commit
f952766fa4
  1. 7
      src/Avalonia.Styling/LogicalTree/ControlLocator.cs
  2. 17
      src/Avalonia.Styling/Styling/Setter.cs
  3. 2
      src/Avalonia.Styling/Styling/TypeNameAndClassSelector.cs

7
src/Avalonia.Styling/LogicalTree/ControlLocator.cs

@ -3,9 +3,6 @@
using System;
using System.Linq;
using System.Reactive.Linq;
using System.Reflection;
using Avalonia.Controls;
using Avalonia.Reactive;
namespace Avalonia.LogicalTree
@ -25,7 +22,7 @@ namespace Avalonia.LogicalTree
private readonly ILogical _relativeTo;
private readonly int _ancestorLevel;
private readonly Type _ancestorType;
ILogical _value;
private ILogical _value;
public ControlTracker(ILogical relativeTo, int ancestorLevel, Type ancestorType)
{
@ -69,7 +66,7 @@ namespace Avalonia.LogicalTree
private void Update()
{
_value = _relativeTo.GetLogicalAncestors()
.Where(x => _ancestorType?.GetTypeInfo().IsAssignableFrom(x.GetType().GetTypeInfo()) ?? true)
.Where(x => _ancestorType?.IsAssignableFrom(x.GetType()) ?? true)
.ElementAtOrDefault(_ancestorLevel);
}
}

17
src/Avalonia.Styling/Styling/Setter.cs

@ -3,9 +3,7 @@
using System;
using System.Reactive.Disposables;
using System.Reflection;
using Avalonia.Animation;
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Metadata;
using Avalonia.Reactive;
@ -92,14 +90,15 @@ namespace Avalonia.Styling
if (binding == null)
{
var template = value as ITemplate;
bool isPropertyOfTypeITemplate = typeof(ITemplate).GetTypeInfo()
.IsAssignableFrom(Property.PropertyType.GetTypeInfo());
if (template != null && !isPropertyOfTypeITemplate)
if (value is ITemplate template)
{
var materialized = template.Build();
value = materialized;
bool isPropertyOfTypeITemplate = typeof(ITemplate).IsAssignableFrom(Property.PropertyType);
if (!isPropertyOfTypeITemplate)
{
var materialized = template.Build();
value = materialized;
}
}
if (activator == null)

2
src/Avalonia.Styling/Styling/TypeNameAndClassSelector.cs

@ -114,7 +114,7 @@ namespace Avalonia.Styling
}
else
{
if (!TargetType.GetTypeInfo().IsAssignableFrom(controlType.GetTypeInfo()))
if (!TargetType.IsAssignableFrom(controlType))
{
return SelectorMatch.NeverThisType;
}

Loading…
Cancel
Save