4 changed files with 70 additions and 36 deletions
@ -0,0 +1,34 @@ |
|||||
|
using System.Linq; |
||||
|
using XamlX; |
||||
|
using XamlX.Ast; |
||||
|
using XamlX.Transform; |
||||
|
using XamlX.Transform.Transformers; |
||||
|
|
||||
|
namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; |
||||
|
|
||||
|
internal class AvaloniaXamlIlSetterTargetTypeMetadataTransformer : IXamlAstTransformer |
||||
|
{ |
||||
|
public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode node) |
||||
|
{ |
||||
|
if (node is XamlAstObjectNode on |
||||
|
&& on.Children.FirstOrDefault(c => c is XamlAstXmlDirective |
||||
|
{ |
||||
|
Namespace: XamlNamespaces.Xaml2006, |
||||
|
Name: "SetterTargetType" |
||||
|
}) is { } typeDirective) |
||||
|
{ |
||||
|
var value = ((XamlAstXmlDirective)typeDirective).Values.Single(); |
||||
|
var type = value is XamlTypeExtensionNode typeNode ? typeNode.Value |
||||
|
: value is XamlAstTextNode tn ? TypeReferenceResolver.ResolveType(context, tn.Text, false, tn, true) |
||||
|
: null; |
||||
|
on.Children.Remove(typeDirective); |
||||
|
|
||||
|
if (type is null) |
||||
|
{ |
||||
|
throw new XamlParseException("Unable to resolve SetterTargetType type", typeDirective); |
||||
|
} |
||||
|
return new AvaloniaXamlIlTargetTypeMetadataNode(on, type, AvaloniaXamlIlTargetTypeMetadataNode.ScopeTypes.Style); |
||||
|
} |
||||
|
return node; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue