Browse Source
Merge pull request #3486 from MarchingCube/refactor-styling-type-info
Remove TypeInfo usage in Avalonia.Styling.
pull/3507/head
Jumar Macato
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
11 additions and
15 deletions
-
src/Avalonia.Styling/LogicalTree/ControlLocator.cs
-
src/Avalonia.Styling/Styling/Setter.cs
-
src/Avalonia.Styling/Styling/TypeNameAndClassSelector.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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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) |
|
|
|
|
|
|
|
@ -114,7 +114,7 @@ namespace Avalonia.Styling |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (!TargetType.GetTypeInfo().IsAssignableFrom(controlType.GetTypeInfo())) |
|
|
|
if (!TargetType.IsAssignableFrom(controlType)) |
|
|
|
{ |
|
|
|
return SelectorMatch.NeverThisType; |
|
|
|
} |
|
|
|
|