Skip to content
This repository was archived by the owner on Jun 28, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Avalonia.NameGenerator/Generator/ResolverExtensions.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 5 deletions src/Avalonia.NameGenerator/Generator/XamlXNameResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions src/Avalonia.NameGenerator/Generator/XamlXViewResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using XamlX;
using XamlX.Ast;
using XamlX.Parsers;
using XamlX.TypeSystem;

namespace Avalonia.NameGenerator.Generator;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -102,4 +99,4 @@ IXamlAstNode IXamlAstVisitor.Visit(IXamlAstNode node)
void IXamlAstVisitor.Push(IXamlAstNode node) { }

void IXamlAstVisitor.Pop() { }
}
}