From ec75657877b6e441de12fbf54be49bf78b49aaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 27 May 2026 15:08:55 +0200 Subject: [PATCH] Make sure all types are fully qualified --- .../DotnetAutomaticInterface/Builder.cs | 7 ++++- ...yOptionalNullableGenericTypes.verified.txt | 20 ++++++++++++ AutomaticInterface/Tests/Methods/Methods.cs | 31 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 AutomaticInterface/Tests/Methods/Methods.FullyQualifyOptionalNullableGenericTypes.verified.txt diff --git a/AutomaticInterface/DotnetAutomaticInterface/Builder.cs b/AutomaticInterface/DotnetAutomaticInterface/Builder.cs index 8ad7296..8f2f147 100644 --- a/AutomaticInterface/DotnetAutomaticInterface/Builder.cs +++ b/AutomaticInterface/DotnetAutomaticInterface/Builder.cs @@ -202,8 +202,13 @@ bool nullableContextEnabled ) { var addNullable = new AddNullableAnnotationSyntaxRewriter(); + // Modify the full parameter display string to add the nullable annotation return addNullable - .Visit(param.DeclaringSyntaxReferences.First().GetSyntax()) + .Visit( + SyntaxFactory.ParseParameterList( + param.ToDisplayString(FullyQualifiedDisplayFormat) + ) + ) .ToFullString(); } return param.ToDisplayString(FullyQualifiedDisplayFormat); diff --git a/AutomaticInterface/Tests/Methods/Methods.FullyQualifyOptionalNullableGenericTypes.verified.txt b/AutomaticInterface/Tests/Methods/Methods.FullyQualifyOptionalNullableGenericTypes.verified.txt new file mode 100644 index 0000000..ffef2fa --- /dev/null +++ b/AutomaticInterface/Tests/Methods/Methods.FullyQualifyOptionalNullableGenericTypes.verified.txt @@ -0,0 +1,20 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +#nullable enable +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")] + public partial interface IDemoClass + { + /// + bool TryStartTransaction(int? param, global::AutomaticInterfaceExample.Types.Model? modelParam = null); + + } +} +#nullable restore diff --git a/AutomaticInterface/Tests/Methods/Methods.cs b/AutomaticInterface/Tests/Methods/Methods.cs index bd0f192..3069d96 100644 --- a/AutomaticInterface/Tests/Methods/Methods.cs +++ b/AutomaticInterface/Tests/Methods/Methods.cs @@ -99,6 +99,37 @@ public bool TryStartTransaction(int? param, int param2 = 0, string data = null, await Verify(Infrastructure.GenerateCode(code)); } + [Fact] + public async Task FullyQualifyOptionalNullableGenericTypes() + { + const string code = """ + + using DotnetAutomaticInterface; + + + namespace AutomaticInterfaceExample { + + namespace Types { + public class Model; + public class Model2; + } + + [GenerateAutomaticInterface] + public class DemoClass + { + public bool TryStartTransaction(int? param, Types.Model modelParam = null) + { + return true; + } + } + + } + + + """; + await Verify(Infrastructure.GenerateCode(code)); + } + [Fact] public async Task AddsPublicMethodToInterface() {