Преглед на файлове

Merge pull request #3486 from MarchingCube/refactor-styling-type-info

Remove TypeInfo usage in Avalonia.Styling.
Jumar Macato преди 5 години
родител
ревизия
e747d572ac

+ 2 - 5
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);
             }
         }

+ 8 - 9
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)

+ 1 - 1
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;
                     }