diff --git a/src/Avalonia.NameGenerator/Generator/ResolverExtensions.cs b/src/Avalonia.NameGenerator/Generator/ResolverExtensions.cs new file mode 100644 index 0000000..529e7b0 --- /dev/null +++ b/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"); + } +} \ No newline at end of file diff --git a/src/Avalonia.NameGenerator/Generator/XamlXNameResolver.cs b/src/Avalonia.NameGenerator/Generator/XamlXNameResolver.cs index 746a81f..e2b4fa2 100644 --- a/src/Avalonia.NameGenerator/Generator/XamlXNameResolver.cs +++ b/src/Avalonia.NameGenerator/Generator/XamlXNameResolver.cs @@ -31,12 +31,8 @@ IXamlAstNode IXamlAstVisitor.Visit(IXamlAstNode node) 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) diff --git a/src/Avalonia.NameGenerator/Generator/XamlXViewResolver.cs b/src/Avalonia.NameGenerator/Generator/XamlXViewResolver.cs index 334574a..2e79934 100644 --- a/src/Avalonia.NameGenerator/Generator/XamlXViewResolver.cs +++ b/src/Avalonia.NameGenerator/Generator/XamlXViewResolver.cs @@ -6,6 +6,7 @@ using XamlX; using XamlX.Ast; using XamlX.Parsers; +using XamlX.TypeSystem; namespace Avalonia.NameGenerator.Generator; @@ -55,19 +56,15 @@ public ResolvedView ResolveView(string xaml) 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 @@ IXamlAstNode IXamlAstVisitor.Visit(IXamlAstNode node) void IXamlAstVisitor.Push(IXamlAstNode node) { } void IXamlAstVisitor.Pop() { } -} \ No newline at end of file +}