Repository: unoplatform/uno
File: src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs (C#)

Code before:
{
	internal partial class XamlFileGenerator
	{
		private const string GlobalPrefix = "global::";
		private const string QualifiedNamespaceMarker = ".";

		private static readonly char[] _dotArray = new[] { '.' };
		private static readonly char[] _parenthesesArray = new[] { '(', ')' };

		private static readonly Dictionary<string, string[]> _knownNamespaces = new Dictionary<string, string[]>
		{
			{
				XamlConstants.PresentationXamlXmlNamespace,
				XamlConstants.Namespaces.PresentationNamespaces
			},
			{
				XamlConstants.XamlXmlNamespace,
				new [] {
					"System",
				}
			},
		};

		private static readonly string[] FrameworkTemplateTypes = new[] { "DataTemplate", "ControlTemplate", "ItemsPanelTemplate" };

		private readonly Dictionary<string, XamlObjectDefinition> _namedResources = new Dictionary<string, XamlObjectDefinition>();
		private readonly List<string> _partials = new List<string>();

		/// <summary>
		/// Names of disambiguated keys associated with resource definitions. These are created for top-level ResourceDictionary declarations only.
		/// </summary>
		private readonly Dictionary<(string? Theme, string ResourceKey), string> _topLevelQualifiedKeys = new Dictionary<(string?, string), string>();
		private readonly Stack<NameScope> _scopeStack = new Stack<NameScope>();
		private readonly Stack<LogicalScope> _logicalScopeStack = new Stack<LogicalScope>();
		private readonly Stack<XLoadScope> _xLoadScopeStack = new Stack<XLoadScope>();
		private int _resourceOwner;
		private readonly XamlFileDefinition _fileDefinition;
		private readonly string _defaultNamespace;
		private readonly RoslynMetadataHelper _metadataHelper;
		private readonly string _fileUniqueId;
		private readonly string[] _analyzerSuppressions;
		private readonly ResourceDetailsCollection _resourceDetailsCollection;
		private int _collectionIndex;
		private int _dictionaryPropertyIndex;
		private int _xBindCounter;
		private string? _themeDictionaryCurrentlyBuilding;
		private readonly XamlGlobalStaticResourcesMap _globalStaticResourcesMap;
		private readonly bool _isUiAutomationMappingEnabled;
		private readonly Dictionary<string, string[]> _uiAutomationMappings;
		private readonly string _defaultLanguage;
		private readonly bool _isHotReloadEnabled;

Review comment (bug):
@MartinZikmund Did you ensure that they are not mutated in any code path? If they are mutated, this will be a very hard-to-investigate bug :)

Code after:
{
	internal partial class XamlFileGenerator
	{
		private const string GlobalPrefix = "global::";
		private const string QualifiedNamespaceMarker = ".";

		private static readonly char[] _dotArray = new[] { '.' };
		private static readonly char[] _parenthesesArray = new[] { '(', ')' };

		private static readonly Dictionary<string, string[]> _knownNamespaces = new Dictionary<string, string[]>
		{
			{
				XamlConstants.PresentationXamlXmlNamespace,
				XamlConstants.Namespaces.PresentationNamespaces
			},
			{
				XamlConstants.XamlXmlNamespace,
				new [] {
					"System",
				}
			},
		};

		private static readonly string[] FrameworkTemplateTypes = new[] { "DataTemplate", "ControlTemplate", "ItemsPanelTemplate" };

		private static readonly XamlType _elementStubXamlType = new XamlType(
			XamlConstants.BaseXamlNamespace,
			"ElementStub",
			new List<XamlType>(),
			new XamlSchemaContext()
		);

		private readonly Dictionary<string, XamlObjectDefinition> _namedResources = new Dictionary<string, XamlObjectDefinition>();
		private readonly List<string> _partials = new List<string>();

		/// <summary>
		/// Names of disambiguated keys associated with resource definitions. These are created for top-level ResourceDictionary declarations only.
		/// </summary>
		private readonly Dictionary<(string? Theme, string ResourceKey), string> _topLevelQualifiedKeys = new Dictionary<(string?, string), string>();
		private readonly Stack<NameScope> _scopeStack = new Stack<NameScope>();
		private readonly Stack<LogicalScope> _logicalScopeStack = new Stack<LogicalScope>();
		private readonly Stack<XLoadScope> _xLoadScopeStack = new Stack<XLoadScope>();
		private int _resourceOwner;
		private readonly XamlFileDefinition _fileDefinition;
		private readonly string _defaultNamespace;
		private readonly RoslynMetadataHelper _metadataHelper;
		private readonly string _fileUniqueId;
		private readonly string[] _analyzerSuppressions;
		private readonly ResourceDetailsCollection _resourceDetailsCollection;
		private int _collectionIndex;
		private int _dictionaryPropertyIndex;