XNameTransformer.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using XamlX;
  2. using XamlX.Ast;
  3. using XamlX.Transform;
  4. namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
  5. {
  6. class XNameTransformer : IXamlAstTransformer
  7. {
  8. /// <summary>
  9. /// Converts x:Name directives to regular Name assignments
  10. /// </summary>
  11. /// <returns></returns>
  12. public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode node)
  13. {
  14. if (node is XamlAstObjectNode on)
  15. {
  16. for (var c =0; c< on.Children.Count;c++)
  17. {
  18. var ch = on.Children[c];
  19. if (ch is XamlAstXmlDirective d
  20. && d.Namespace == XamlNamespaces.Xaml2006
  21. && d.Name == "Name")
  22. on.Children[c] = new XamlAstXamlPropertyValueNode(d,
  23. new XamlAstNamePropertyReference(d, on.Type, "Name", on.Type),
  24. d.Values);
  25. }
  26. }
  27. return node;
  28. }
  29. }
  30. }