using System;
using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGeneration.Extensions;
///
/// Extension methods for types.
///
internal static class IPropertySymbolExtensions
{
///
/// Gets the fully qualified metadata name for a given instance.
///
/// The input instance.
/// The fully qualified metadata name for .
public static string GetFullyQualifiedMetadataName(this IPropertySymbol symbol)
{
using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
symbol.ContainingType!.AppendFullyQualifiedMetadataName(in builder);
if (symbol.IsIndexer)
{
// Add the ".this[...]" suffix (parameters will be added below)
builder.AddRange(".this[".AsSpan());
bool isFirstParameter = true;
// If the property is an indexer, also includes the parameters
foreach (IParameterSymbol parameter in symbol.Parameters)
{
// Append the leading ', ' if needed
if (isFirstParameter)
{
isFirstParameter = false;
}
else
{
builder.AddRange(", ".AsSpan());
}
parameter.Type.AppendFullyQualifiedMetadataName(in builder);
}
// Add the closing bracket for ".this[...]"
builder.Add(']');
}
else
{
// For normal properties, just append the name after the containing type
builder.Add('.');
builder.AddRange(symbol.Name.AsSpan());
}
return builder.ToString();
}
}