1
1
using System . Linq ;
2
2
using XamlX . Ast ;
3
3
using XamlX . Transform ;
4
+ using XamlX . Transform . Transformers ;
4
5
using XamlX . TypeSystem ;
5
6
6
7
namespace Avalonia . Markup . Xaml . XamlIl . CompilerExtensions . Transformers
@@ -22,26 +23,19 @@ public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode nod
22
23
IXamlAstTypeReference targetType ;
23
24
24
25
var templatableBaseType = context . Configuration . TypeSystem . GetType ( "Avalonia.Controls.Control" ) ;
25
-
26
- if ( ( tt ? . Values . FirstOrDefault ( ) is XamlTypeExtensionNode tn ) )
27
- {
28
- targetType = tn . Value ;
29
- }
30
- else
26
+
27
+ targetType = tt ? . Values . FirstOrDefault ( ) switch
31
28
{
32
- var parentScope = context . ParentNodes ( ) . OfType < AvaloniaXamlIlTargetTypeMetadataNode > ( )
33
- . FirstOrDefault ( ) ;
34
- if ( parentScope ? . ScopeType == AvaloniaXamlIlTargetTypeMetadataNode . ScopeTypes . Style )
35
- targetType = parentScope . TargetType ;
36
- else if ( context . ParentNodes ( ) . Skip ( 1 ) . FirstOrDefault ( ) is XamlAstObjectNode directParentNode
37
- && templatableBaseType . IsAssignableFrom ( directParentNode . Type . GetClrType ( ) ) )
38
- targetType = directParentNode . Type ;
39
- else
40
- targetType = new XamlAstClrTypeReference ( node ,
41
- templatableBaseType , false ) ;
42
- }
43
-
44
-
29
+ XamlTypeExtensionNode tn => tn . Value ,
30
+ XamlAstTextNode textNode => TypeReferenceResolver . ResolveType ( context , textNode . Text , false , textNode , true ) ,
31
+ _ when context . ParentNodes ( )
32
+ . OfType < AvaloniaXamlIlTargetTypeMetadataNode > ( )
33
+ . FirstOrDefault ( ) is { ScopeType : AvaloniaXamlIlTargetTypeMetadataNode . ScopeTypes . Style } parentScope => parentScope . TargetType ,
34
+ _ when context . ParentNodes ( ) . Skip ( 1 ) . FirstOrDefault ( ) is XamlAstObjectNode directParentNode
35
+ && templatableBaseType . IsAssignableFrom ( directParentNode . Type . GetClrType ( ) ) => directParentNode . Type ,
36
+ _ => new XamlAstClrTypeReference ( node ,
37
+ templatableBaseType , false )
38
+ } ;
45
39
46
40
return new AvaloniaXamlIlTargetTypeMetadataNode ( on , targetType ,
47
41
AvaloniaXamlIlTargetTypeMetadataNode . ScopeTypes . ControlTemplate ) ;
@@ -59,7 +53,7 @@ public enum ScopeTypes
59
53
ControlTemplate ,
60
54
Transitions
61
55
}
62
-
56
+
63
57
public AvaloniaXamlIlTargetTypeMetadataNode ( IXamlAstValueNode value , IXamlAstTypeReference targetType ,
64
58
ScopeTypes type )
65
59
: base ( value , value )
0 commit comments