Skip to content
This repository was archived by the owner on Jun 28, 2023. It is now read-only.

Commit da39281

Browse files
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.
1 parent 1d6b309 commit da39281

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Linq;
2+
using XamlX.TypeSystem;
3+
4+
namespace Avalonia.NameGenerator.Generator;
5+
6+
internal static class ResolverExtensions
7+
{
8+
public static bool IsAvaloniaControl(this IXamlType clrType)
9+
{
10+
return clrType.HasControlBaseType() || clrType.HasIControlInterface();
11+
}
12+
13+
private static bool HasControlBaseType(this IXamlType clrType)
14+
{
15+
// Check for the base type since IControl interface is removed.
16+
// https://github.com/AvaloniaUI/Avalonia/pull/9553
17+
if (clrType.FullName == "Avalonia.Controls.Control")
18+
return true;
19+
20+
if (clrType.BaseType != null)
21+
return IsAvaloniaControl(clrType.BaseType);
22+
23+
return false;
24+
}
25+
26+
private static bool HasIControlInterface(this IXamlType clrType)
27+
{
28+
return clrType
29+
.Interfaces
30+
.Any(abstraction => abstraction.IsInterface &&
31+
abstraction.FullName == "Avalonia.Controls.IControl");
32+
}
33+
}

src/Avalonia.NameGenerator/Generator/XamlXNameResolver.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@ IXamlAstNode IXamlAstVisitor.Visit(IXamlAstNode node)
3131
return node;
3232

3333
var clrType = objectNode.Type.GetClrType();
34-
var isAvaloniaControl = clrType
35-
.Interfaces
36-
.Any(abstraction => abstraction.IsInterface &&
37-
abstraction.FullName == "Avalonia.Controls.IControl");
3834

39-
if (!isAvaloniaControl)
35+
if (!clrType.IsAvaloniaControl())
4036
return node;
4137

4238
foreach (var child in objectNode.Children)

src/Avalonia.NameGenerator/Generator/XamlXViewResolver.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using XamlX;
77
using XamlX.Ast;
88
using XamlX.Parsers;
9+
using XamlX.TypeSystem;
910

1011
namespace Avalonia.NameGenerator.Generator;
1112

@@ -55,19 +56,15 @@ public ResolvedView ResolveView(string xaml)
5556
return null;
5657
}
5758
}
58-
59+
5960
IXamlAstNode IXamlAstVisitor.Visit(IXamlAstNode node)
6061
{
6162
if (node is not XamlAstObjectNode objectNode)
6263
return node;
6364

6465
var clrType = objectNode.Type.GetClrType();
65-
var isAvaloniaControl = clrType
66-
.Interfaces
67-
.Any(abstraction => abstraction.IsInterface &&
68-
abstraction.FullName == "Avalonia.Controls.IControl");
6966

70-
if (!isAvaloniaControl)
67+
if (!clrType.IsAvaloniaControl())
7168
return node;
7269

7370
foreach (var child in objectNode.Children)
@@ -102,4 +99,4 @@ IXamlAstNode IXamlAstVisitor.Visit(IXamlAstNode node)
10299
void IXamlAstVisitor.Push(IXamlAstNode node) { }
103100

104101
void IXamlAstVisitor.Pop() { }
105-
}
102+
}

0 commit comments

Comments
 (0)