Browse Source

fix: Check for Control Base Type Since IControl Interface is Removed (#100)

* Check for Control base type since IControl interface is removed
* Apply base type check fix to name resolver too.
pull/10407/head
Yusuf Tarık Günaydın 3 years ago
committed by GitHub
parent
commit
da39281ecf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      src/Avalonia.NameGenerator/Generator/ResolverExtensions.cs
  2. 6
      src/Avalonia.NameGenerator/Generator/XamlXNameResolver.cs
  3. 11
      src/Avalonia.NameGenerator/Generator/XamlXViewResolver.cs

33
src/Avalonia.NameGenerator/Generator/ResolverExtensions.cs

@ -0,0 +1,33 @@
using System.Linq;
using XamlX.TypeSystem;
namespace Avalonia.NameGenerator.Generator;
internal static class ResolverExtensions
{
public static bool IsAvaloniaControl(this IXamlType clrType)
{
return clrType.HasControlBaseType() || clrType.HasIControlInterface();
}
private static bool HasControlBaseType(this IXamlType clrType)
{
// Check for the base type since IControl interface is removed.
// https://github.com/AvaloniaUI/Avalonia/pull/9553
if (clrType.FullName == "Avalonia.Controls.Control")
return true;
if (clrType.BaseType != null)
return IsAvaloniaControl(clrType.BaseType);
return false;
}
private static bool HasIControlInterface(this IXamlType clrType)
{
return clrType
.Interfaces
.Any(abstraction => abstraction.IsInterface &&
abstraction.FullName == "Avalonia.Controls.IControl");
}
}

6
src/Avalonia.NameGenerator/Generator/XamlXNameResolver.cs

@ -31,12 +31,8 @@ internal class XamlXNameResolver : INameResolver, IXamlAstVisitor
return node;
var clrType = objectNode.Type.GetClrType();
var isAvaloniaControl = clrType
.Interfaces
.Any(abstraction => abstraction.IsInterface &&
abstraction.FullName == "Avalonia.Controls.IControl");
if (!isAvaloniaControl)
if (!clrType.IsAvaloniaControl())
return node;
foreach (var child in objectNode.Children)

11
src/Avalonia.NameGenerator/Generator/XamlXViewResolver.cs

@ -6,6 +6,7 @@ using Avalonia.NameGenerator.Domain;
using XamlX;
using XamlX.Ast;
using XamlX.Parsers;
using XamlX.TypeSystem;
namespace Avalonia.NameGenerator.Generator;
@ -55,19 +56,15 @@ internal class XamlXViewResolver : IViewResolver, IXamlAstVisitor
return null;
}
}
IXamlAstNode IXamlAstVisitor.Visit(IXamlAstNode node)
{
if (node is not XamlAstObjectNode objectNode)
return node;
var clrType = objectNode.Type.GetClrType();
var isAvaloniaControl = clrType
.Interfaces
.Any(abstraction => abstraction.IsInterface &&
abstraction.FullName == "Avalonia.Controls.IControl");
if (!isAvaloniaControl)
if (!clrType.IsAvaloniaControl())
return node;
foreach (var child in objectNode.Children)
@ -102,4 +99,4 @@ internal class XamlXViewResolver : IViewResolver, IXamlAstVisitor
void IXamlAstVisitor.Push(IXamlAstNode node) { }
void IXamlAstVisitor.Pop() { }
}
}

Loading…
Cancel
Save