Repository: AvaloniaUI/Avalonia
File: src/tools/Avalonia.Generators/NameGenerator/AvaloniaNameIncrementalGenerator.cs (C#)

Code before:
                    _ => throw new ArgumentOutOfRangeException()
                };
                var fileName = options.AvaloniaNameGeneratorViewFileNamingStrategy switch
                {
                    ViewFileNamingStrategy.ClassName => $"{view.ClassName}.g.cs",
                    ViewFileNamingStrategy.NamespaceAndClassName => $"{view.Namespace}.{view.ClassName}.g.cs",
                    _ => throw new ArgumentOutOfRangeException(
                        nameof(ViewFileNamingStrategy), options.AvaloniaNameGeneratorViewFileNamingStrategy,
                        "Unknown naming strategy!")
                };

                var generatedPartialClass = codeGenerator.GenerateCode(
                    info.View.ClassName,
                    info.View.Namespace,
                    info.View.Names);

                context.AddSource(fileName, generatedPartialClass);
            }
        });
    }

    /// <summary>
    /// Fallback in case XAML parsing fails. Extracts just the class name and namespace of the root element.
    /// </summary>
    private static ResolvedXmlView? TryExtractTypeFromXml(string xaml)
    {
        try
        {
            var document = XDocument.Parse(xaml);
            var classValue = document.Root.Attribute(XName.Get("Class", XamlNamespaces.Xaml2006))?.Value;
            if (classValue?.LastIndexOf('.') is { } lastDotIndex && lastDotIndex != -1)
            {
                return new(classValue.Substring(lastDotIndex + 1), classValue.Substring(0, lastDotIndex), EquatableList<ResolvedXmlName>.Empty);
            }
        }
        catch
        {
            // ignore
        }
        return null;
    }

    private static LinePositionSpan GetLinePositionSpan(XmlException ex)
    {
        var position = new LinePosition(Math.Max(0, ex.LineNumber - 1), Math.Max(0, ex.LinePosition - 1));
        return new(position, position);
    }

    internal record XmlClassInfo(
        string FilePath,
        ResolvedXmlView? XmlView,

Review comment (suggestion):
I am surprised here, as it felt backwards to fallback to XDocument. Because I thought we use more reliable [GuiLabs.Language.Xml](https://www.nuget.org/packages/GuiLabs.Language.Xml) for generator here (see [GuiLabsXamlParser.cs](https://github.com/kekekeks/XamlX/blob/master/src/XamlX.Parser.GuiLabs/GuiLabsXamlParser.cs)). But it looks like generator-side change was never implemented. 

In short, GuiLabs.Language.Xml should be a much better default here, allowing to parse partial or incomplete XML, with proper transformable nodes, which is perfect for text editors. That's what we also use with new VS extension.

Code after:
                var fileName = options.AvaloniaNameGeneratorViewFileNamingStrategy switch
                {
                    ViewFileNamingStrategy.ClassName => $"{view.ClassName}.g.cs",
                    ViewFileNamingStrategy.NamespaceAndClassName => $"{view.Namespace}.{view.ClassName}.g.cs",
                    _ => throw new ArgumentOutOfRangeException(
                        nameof(ViewFileNamingStrategy), options.AvaloniaNameGeneratorViewFileNamingStrategy,
                        "Unknown naming strategy!")
                };

                var generatedPartialClass = codeGenerator.GenerateCode(
                    info.View.ClassName,
                    info.View.Namespace,
                    info.View.Names);

                context.AddSource(fileName, generatedPartialClass);
            }
        });
    }

    private static DiagnosticFactory GetInternalErrorDiagnostic(FileLinePositionSpan location, Exception ex) =>
        new(NameGeneratorDiagnostics.InternalError, location, new([ex.ToString().Replace('\n', '*').Replace('\r', '*')]));

    /// <summary>
    /// Fallback in case XAML parsing fails. Extracts just the class name and namespace of the root element.
    /// </summary>
    private static ResolvedXmlView? TryExtractTypeFromXml(string xaml)
    {
        try
        {
            var document = XDocument.Parse(xaml);
            var classValue = document.Root.Attribute(XName.Get("Class", XamlNamespaces.Xaml2006))?.Value;
            if (classValue?.LastIndexOf('.') is { } lastDotIndex && lastDotIndex != -1)
            {
                return new(classValue.Substring(lastDotIndex + 1), classValue.Substring(0, lastDotIndex), EquatableList<ResolvedXmlName>.Empty);
            }
        }
        catch
        {
            // ignore
        }
        return null;
    }

    private static LinePositionSpan GetLinePositionSpan(XmlException ex)
    {
        var position = new LinePosition(Math.Max(0, ex.LineNumber - 1), Math.Max(0, ex.LinePosition - 1));
        return new(position, position);
    }

    internal record XmlClassInfo(
        string FilePath,