Browse Source

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

pull/3486/head
Dariusz Komosinski 7 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;
using System.Linq; using System.Linq;
using System.Reactive.Linq;
using System.Reflection;
using Avalonia.Controls;
using Avalonia.Reactive; using Avalonia.Reactive;
namespace Avalonia.LogicalTree namespace Avalonia.LogicalTree
@ -25,7 +22,7 @@ namespace Avalonia.LogicalTree
private readonly ILogical _relativeTo; private readonly ILogical _relativeTo;
private readonly int _ancestorLevel; private readonly int _ancestorLevel;
private readonly Type _ancestorType; private readonly Type _ancestorType;
ILogical _value; private ILogical _value;
public ControlTracker(ILogical relativeTo, int ancestorLevel, Type ancestorType) public ControlTracker(ILogical relativeTo, int ancestorLevel, Type ancestorType)
{ {
@ -69,7 +66,7 @@ namespace Avalonia.LogicalTree
private void Update() private void Update()
{ {
_value = _relativeTo.GetLogicalAncestors() _value = _relativeTo.GetLogicalAncestors()
.Where(x => _ancestorType?.GetTypeInfo().IsAssignableFrom(x.GetType().GetTypeInfo()) ?? true) .Where(x => _ancestorType?.IsAssignableFrom(x.GetType()) ?? true)
.ElementAtOrDefault(_ancestorLevel); .ElementAtOrDefault(_ancestorLevel);
} }
} }

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

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

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

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

Loading…
Cancel
Save