mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-08-15 18:44:57 +00:00
Ensure that parameters are written with their fully qualified type name
This commit is contained in:
+7
-7
@@ -6,11 +6,11 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Generator
|
||||
{
|
||||
public class ParameterSyntaxRewriter : CSharpSyntaxRewriter
|
||||
public class DeclarationSyntaxRewriter : CSharpSyntaxRewriter
|
||||
{
|
||||
readonly SemanticModel _semanticModel;
|
||||
|
||||
public ParameterSyntaxRewriter(SemanticModel semanticModel)
|
||||
public DeclarationSyntaxRewriter(SemanticModel semanticModel)
|
||||
{
|
||||
_semanticModel = semanticModel;
|
||||
}
|
||||
@@ -19,11 +19,12 @@ namespace EntityFrameworkCore.Projectables.Generator
|
||||
{
|
||||
var visitedNode = base.VisitIdentifierName(node);
|
||||
|
||||
var symbol = _semanticModel.GetDeclaredSymbol(visitedNode);
|
||||
var symbolInfo = _semanticModel.GetSymbolInfo(visitedNode);
|
||||
|
||||
if (symbol is not null)
|
||||
if (symbolInfo.Symbol is not null)
|
||||
{
|
||||
return SyntaxFactory.IdentifierName(symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
|
||||
return SyntaxFactory.IdentifierName(symbolInfo.Symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))
|
||||
.WithTriviaFrom(node);
|
||||
}
|
||||
|
||||
return visitedNode;
|
||||
@@ -53,8 +54,7 @@ namespace EntityFrameworkCore.Projectables.Generator
|
||||
if (typeInfo.Type.TypeKind is not TypeKind.Struct)
|
||||
{
|
||||
return Visit(node.ElementType)
|
||||
.WithLeadingTrivia(node.GetLeadingTrivia())
|
||||
.WithTrailingTrivia(node.GetTrailingTrivia());
|
||||
.WithTriviaFrom(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ namespace EntityFrameworkCore.Projectables.Generator
|
||||
.FirstOrDefault();
|
||||
|
||||
var expressionSyntaxRewriter = new ExpressionSyntaxRewriter(memberSymbol.ContainingType, semanticModel, nullConditionalRewriteSupport, context);
|
||||
var parameterSyntaxRewriter = new ParameterSyntaxRewriter(semanticModel);
|
||||
var returnTypeSyntaxRewriter = new ReturnTypeSyntaxRewriter(semanticModel);
|
||||
var declarationSyntaxRewriter = new DeclarationSyntaxRewriter(semanticModel);
|
||||
|
||||
var descriptor = new ProjectableDescriptor {
|
||||
ClassName = memberSymbol.ContainingType.Name,
|
||||
@@ -100,11 +99,11 @@ namespace EntityFrameworkCore.Projectables.Generator
|
||||
return null;
|
||||
}
|
||||
|
||||
var returnType = returnTypeSyntaxRewriter.Visit(methodDeclarationSyntax.ReturnType);
|
||||
var returnType = declarationSyntaxRewriter.Visit(methodDeclarationSyntax.ReturnType);
|
||||
|
||||
descriptor.ReturnTypeName = returnType.ToString();
|
||||
descriptor.Body = expressionSyntaxRewriter.Visit(methodDeclarationSyntax.ExpressionBody.Expression);
|
||||
foreach (var additionalParameter in ((ParameterListSyntax)parameterSyntaxRewriter.Visit(methodDeclarationSyntax.ParameterList)).Parameters)
|
||||
foreach (var additionalParameter in ((ParameterListSyntax)declarationSyntaxRewriter.Visit(methodDeclarationSyntax.ParameterList)).Parameters)
|
||||
{
|
||||
descriptor.ParametersList = descriptor.ParametersList.AddParameters(additionalParameter);
|
||||
}
|
||||
@@ -118,7 +117,7 @@ namespace EntityFrameworkCore.Projectables.Generator
|
||||
return null;
|
||||
}
|
||||
|
||||
var returnType = returnTypeSyntaxRewriter.Visit(propertyDeclarationSyntax.Type);
|
||||
var returnType = declarationSyntaxRewriter.Visit(propertyDeclarationSyntax.Type);
|
||||
|
||||
descriptor.ReturnTypeName = returnType.ToString();
|
||||
descriptor.Body = expressionSyntaxRewriter.Visit(propertyDeclarationSyntax.ExpressionBody.Expression);
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Generator
|
||||
{
|
||||
public class ReturnTypeSyntaxRewriter : CSharpSyntaxRewriter
|
||||
{
|
||||
readonly SemanticModel _semanticModel;
|
||||
|
||||
public ReturnTypeSyntaxRewriter(SemanticModel semanticModel)
|
||||
{
|
||||
_semanticModel = semanticModel;
|
||||
}
|
||||
|
||||
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node)
|
||||
{
|
||||
var visitedNode = base.VisitIdentifierName(node);
|
||||
|
||||
var symbolInfo = _semanticModel.GetSymbolInfo(visitedNode);
|
||||
|
||||
if (symbolInfo.Symbol is not null)
|
||||
{
|
||||
return SyntaxFactory.IdentifierName(symbolInfo.Symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
|
||||
}
|
||||
|
||||
return visitedNode;
|
||||
}
|
||||
|
||||
public override SyntaxNode? VisitNullableType(NullableTypeSyntax node)
|
||||
{
|
||||
var typeInfo = _semanticModel.GetTypeInfo(node);
|
||||
if (typeInfo.Type is not null)
|
||||
{
|
||||
if (typeInfo.Type.TypeKind is not TypeKind.Struct)
|
||||
{
|
||||
return Visit(node.ElementType)
|
||||
.WithLeadingTrivia(node.GetLeadingTrivia())
|
||||
.WithTrailingTrivia(node.GetTrailingTrivia());
|
||||
}
|
||||
}
|
||||
|
||||
return base.VisitNullableType(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user