Enable assembly defaults, update analyzer

このコミットが含まれているのは:
Sergio Pedri committed 2023-09-27 15:03:06 +02:00
1 親 dd8f221905
コミット e5daf558ec
10ファイル変更
+217 -71

検索条件に一致するファイルはありません

+34
ファイルの表示
@@ -2,6 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGeneration.Extensions;
@@ -11,6 +14,37 @@ namespace ComputeSharp.SourceGeneration.Extensions;
/// </summary>
internal static class CompilationExtensions
{
/// <summary>
/// Tries to build a set of <see cref="INamedTypeSymbol"/> instances form the input mapping of names.
/// </summary>
/// <param name="compilation">The <see cref="Compilation"/> to consider for analysis.</param>
/// <param name="fullyQualifiedTypeNames">The input fully qualified type names.</param>
/// <param name="typeSymbols">The resulting mapping of resolved <see cref="INamedTypeSymbol"/> instances.</param>
/// <returns>Whether all requested <see cref="INamedTypeSymbol"/> instances could be resolved.</returns>
public static bool TryBuildNamedTypeSymbolSet(
this Compilation compilation,
IEnumerable<string> fullyQualifiedTypeNames,
[NotNullWhen(true)] out ImmutableHashSet<INamedTypeSymbol>? typeSymbols)
{
ImmutableHashSet<INamedTypeSymbol>.Builder builder = ImmutableHashSet.CreateBuilder<INamedTypeSymbol>(SymbolEqualityComparer.Default);
foreach (string fullyQualifiedTypeName in fullyQualifiedTypeNames)
{
if (compilation.GetTypeByMetadataName(fullyQualifiedTypeName) is not INamedTypeSymbol typeSymbol)
{
typeSymbols = null;
return false;
}
_ = builder.Add(typeSymbol);
}
typeSymbols = builder.ToImmutable();
return true;
}
/// <summary>
/// <para>
/// Checks whether or not a type with a specified metadata name is accessible from a given <see cref="Compilation"/> instance.