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()
{