Merge pull request #138 from unoplatform/dev/jela/sourcegen-update

fix: Uno.Equality ambiguity with internal uno types
This commit is contained in:
Jérôme Laban 2021-12-07 16:23:10 -05:00 коммит произвёл GitHub
Родитель 4990c59804 281827e0d9
Коммит fa24add31c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
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();