diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationInfo.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationInfo.cs index 76cc41329893..47ad5eae8904 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationInfo.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationInfo.cs @@ -1,8 +1,6 @@ #nullable enable -using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Globalization; namespace Uno.UI.SourceGenerators.XamlGenerator diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationRunFileInfo.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationRunFileInfo.cs index bdfe477a6617..33006733a776 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationRunFileInfo.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationRunFileInfo.cs @@ -8,13 +8,13 @@ namespace Uno.UI.SourceGenerators.XamlGenerator { internal record GenerationRunFileInfo(GenerationRunInfo RunInfo, string FileId) { - private Dictionary _appliedTypes = new Dictionary(); + private Dictionary _appliedTypes = new Dictionary(); internal string? ComponentCode { get; set; } - internal IReadOnlyDictionary AppliedTypes => _appliedTypes; + internal IReadOnlyDictionary AppliedTypes => _appliedTypes; - internal void SetAppliedTypes(Dictionary appliedTypes) + internal void SetAppliedTypes(Dictionary appliedTypes) { foreach (var type in appliedTypes) { diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs index 584d2626aa28..41c97977efe2 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs @@ -145,7 +145,10 @@ internal partial class XamlFileGenerator /// /// Information about types used in .Apply() scenarios /// - private readonly Dictionary _xamlAppliedTypes = new Dictionary(); + /// + /// The key of the dictionary is the globalized fully qualified name. + /// + private readonly Dictionary _xamlAppliedTypes = new(); private readonly INamedTypeSymbol _assemblyMetadataSymbol; @@ -655,11 +658,11 @@ private void BuildXamlApplyBlocks(IndentedStringBuilder writer) { foreach (var typeInfo in _xamlAppliedTypes) { - writer.AppendLineIndented($"public delegate void XamlApplyHandler{typeInfo.Value}({GetGlobalizedTypeName(typeInfo.Key.ToString())} instance);"); + writer.AppendLineIndented($"public delegate void XamlApplyHandler{typeInfo.Value}({typeInfo.Key} instance);"); writer.AppendLineIndented($"[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]"); using (writer.BlockInvariant( - $"public static {GetGlobalizedTypeName(typeInfo.Key.ToString())} {_fileUniqueId}_XamlApply(this {GetGlobalizedTypeName(typeInfo.Key.ToString())} instance, XamlApplyHandler{typeInfo.Value} handler)" + $"public static {typeInfo.Key} {_fileUniqueId}_XamlApply(this {typeInfo.Key} instance, XamlApplyHandler{typeInfo.Value} handler)" )) { writer.AppendLineIndented($"handler(instance);"); @@ -4169,10 +4172,11 @@ private XamlLazyApplyBlockIIndentedStringBuilder CreateApplyBlock(IIndentedStrin if (appliedType != null) { - if (!_xamlAppliedTypes.TryGetValue(appliedType, out var appliedTypeIndex)) + var globalizedFullyQualifiedAppliedType = GetGlobalizedTypeName(appliedType.ToString()); + if (!_xamlAppliedTypes.TryGetValue(globalizedFullyQualifiedAppliedType, out var appliedTypeIndex)) { appliedTypeIndex = _xamlAppliedTypes.Count; - _xamlAppliedTypes.Add(appliedType, _xamlAppliedTypes.Count); + _xamlAppliedTypes.Add(globalizedFullyQualifiedAppliedType, _xamlAppliedTypes.Count); } if (_isHotReloadEnabled)