Use fully qualified names to reduce namespace clashes. (#68)

* Use fully qualified names to reduce namespace clashes.

* Small code style fixes.

* Make properties in ProxyData immutable.

* Remove clutter by joining TrimEnd() to previous line.

* Introduce Extension method to retrieve ITypeSymbol FullyQualifiedDisplayString

* Fixed some code issues.

* Fixed method call in BaseGenerator

* Refactor metadata name
This commit is contained in:
David
2024-04-28 10:25:50 +02:00
committed by GitHub
parent 68864378d0
commit 39d85588e6
56 changed files with 1123 additions and 1146 deletions
@@ -1,13 +1,16 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using ProxyInterfaceSourceGenerator.Extensions;
using ProxyInterfaceSourceGenerator.Types;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
namespace ProxyInterfaceSourceGenerator.SyntaxReceiver;
internal static class AttributeArgumentListParser
{
public static ProxyInterfaceGeneratorAttributeArguments ParseAttributeArguments(AttributeArgumentListSyntax? argumentList)
public static ProxyInterfaceGeneratorAttributeArguments ParseAttributeArguments(AttributeArgumentListSyntax? argumentList, SemanticModel semanticModel)
{
if (argumentList is null || argumentList.Arguments.Count is < 1 or > 3)
{
@@ -15,9 +18,9 @@ internal static class AttributeArgumentListParser
}
ProxyInterfaceGeneratorAttributeArguments result;
if (TryParseAsType(argumentList.Arguments[0].Expression, out var rawTypeValue))
if (TryParseAsType(argumentList.Arguments[0].Expression, semanticModel, out var fullyQualifiedDisplayString, out var metadataName))
{
result = new ProxyInterfaceGeneratorAttributeArguments(rawTypeValue);
result = new ProxyInterfaceGeneratorAttributeArguments(fullyQualifiedDisplayString, metadataName);
}
else
{
@@ -54,13 +57,18 @@ internal static class AttributeArgumentListParser
return false;
}
private static bool TryParseAsType(ExpressionSyntax expressionSyntax, [NotNullWhen(true)] out string? rawTypeName)
private static bool TryParseAsType(ExpressionSyntax expressionSyntax, SemanticModel semanticModel, [NotNullWhen(true)] out string? fullyQualifiedDisplayString, [NotNullWhen(true)] out string? metadataName)
{
rawTypeName = null;
fullyQualifiedDisplayString = null;
metadataName = null;
if (expressionSyntax is TypeOfExpressionSyntax typeOfExpressionSyntax)
{
rawTypeName = typeOfExpressionSyntax.Type.ToString();
var typeInfo = semanticModel.GetTypeInfo(typeOfExpressionSyntax.Type);
var typeSymbol = typeInfo.Type!;
metadataName = typeSymbol.GetFullMetadataName();
fullyQualifiedDisplayString = typeSymbol.ToFullyQualifiedDisplayString();
return true;
}