fix: Uno.Equality ambiguity with internal uno types

This workaround can be removed once [this type](574a441497/src/Uno.Foundation/Uno.Core.Extensions/Uno.Core.Extensions.Equality/IKeyEquatable.cs (L26)) has been renamed.
This commit is contained in:
Jerome Laban 2021-12-07 16:02:28 -05:00
Родитель cdb887ae20
Коммит 281827e0d9
1 изменённых файлов: 20 добавлений и 0 удалений

Просмотреть файл

@ -131,6 +131,8 @@ namespace Uno
_dataAnnonationsKeyAttributeSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.DataAnnotations.KeyAttribute");
_isPureAttributePresent = context.Compilation.GetTypeByMetadataName("System.Diagnostics.Contracts.Pure") != null;
ApplyWorkaroundForUnoEqualityAssembly(context);
_generateKeyEqualityCode = _iKeyEquatableSymbol != null;
foreach (var type in EnumerateEqualityTypesToGenerate())
@ -139,6 +141,24 @@ namespace Uno
}
}
private void ApplyWorkaroundForUnoEqualityAssembly(SourceGeneratorContext context)
{
if (_iKeyEquatableSymbol == null && _iKeyEquatableGenericSymbol == null)
{
// Workaround for internal types duplicated in Uno.Foundation and other Uno assemblies
// causing context.Compilation.GetTypeByMetadataName to return null because of the ambiguity.
if (context.Compilation.ExternalReferences.FirstOrDefault(r => r.Display.EndsWith("Uno.Core.Extensions.Equality.dll", StringComparison.OrdinalIgnoreCase)) is MetadataReference equalityRef)
{
if (context.Compilation.GetAssemblyOrModuleSymbol(equalityRef) is IAssemblySymbol assemblySymbol)
{
_iKeyEquatableSymbol = assemblySymbol.GetTypeByMetadataName("Uno.Equality.IKeyEquatable");
_iKeyEquatableGenericSymbol = assemblySymbol.GetTypeByMetadataName("Uno.Equality.IKeyEquatable`1");
}
}
}
}
private void GenerateEquality(INamedTypeSymbol typeSymbol)
{
var builder = new IndentedStringBuilder();