File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,10 @@ public CompilationUnitSyntax GetCompilationUnit(
68
68
69
69
if ( Namespace is "" )
70
70
{
71
+ // Special case for top level types with no namespace: we need to re-add the
72
+ // inheritdoc XML comment, as otherwise the call below would remove it.
73
+ syntaxTriviaList = syntaxTriviaList . Add ( Comment ( "/// <inheritdoc/>" ) ) ;
74
+
71
75
// If there is no namespace, attach the pragma directly to the declared type,
72
76
// and skip the namespace declaration. This will produce code as follows:
73
77
//
Original file line number Diff line number Diff line change @@ -1538,6 +1538,41 @@ public string? A
1538
1538
#endif
1539
1539
}
1540
1540
1541
+ [ TestMethod ]
1542
+ public void RelayCommandMethodInTopLevelTypeWithNoNamespace_PreservesInheritdoc ( )
1543
+ {
1544
+ string source = """
1545
+ using CommunityToolkit.Mvvm.Input;
1546
+
1547
+ partial class MyViewModel
1548
+ {
1549
+ [RelayCommand]
1550
+ private void Test()
1551
+ {
1552
+ }
1553
+ }
1554
+ """ ;
1555
+
1556
+ string result = """
1557
+ // <auto-generated/>
1558
+ #pragma warning disable
1559
+ #nullable enable
1560
+ /// <inheritdoc/>
1561
+ partial class MyViewModel
1562
+ {
1563
+ /// <summary>The backing field for <see cref="TestCommand"/>.</summary>
1564
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.2.0.0")]
1565
+ private global::CommunityToolkit.Mvvm.Input.RelayCommand? testCommand;
1566
+ /// <summary>Gets an <see cref="global::CommunityToolkit.Mvvm.Input.IRelayCommand"/> instance wrapping <see cref="Test"/>.</summary>
1567
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "8.2.0.0")]
1568
+ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
1569
+ public global::CommunityToolkit.Mvvm.Input.IRelayCommand TestCommand => testCommand ??= new global::CommunityToolkit.Mvvm.Input.RelayCommand(new global::System.Action(Test));
1570
+ }
1571
+ """ ;
1572
+
1573
+ VerifyGenerateSources ( source , new [ ] { new RelayCommandGenerator ( ) } , ( "MyViewModel.Test.g.cs" , result ) ) ;
1574
+ }
1575
+
1541
1576
/// <summary>
1542
1577
/// Generates the requested sources
1543
1578
/// </summary>
You can’t perform that action at this time.
0 commit comments