Skip to content

Add boilerplate documentation to generated types #30259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Controls/src/SourceGen/CodeBehindGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ static void GenerateXamlCodeBehind(XamlProjectItem? xamlItem, Compilation compil

sb.AppendLine($"namespace {rootClrNamespace}");
sb.AppendLine("{");
sb.AppendLine($"\t/// <summary>");
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public docs live in XML under /docs/. Please update the relevant docs XML to describe the new boilerplate documentation feature so public documentation aligns with code changes.

Copilot uses AI. Check for mistakes.

sb.AppendLine($"\t/// Generated XAML code behind for {projItem.RelativePath}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a great summary to end up in class documentation - those paths doesn't make sense in IntelliSense. Seems cleaner to just add a [GeneratedCode] attribute.

sb.AppendLine($"\t/// </summary>");
sb.AppendLine($"\t[global::Microsoft.Maui.Controls.Xaml.XamlFilePath(\"{projItem.RelativePath?.Replace("\\", "\\\\")}\")]");
if (addXamlCompilationAttribute)
{
Expand All @@ -320,6 +323,9 @@ static void GenerateXamlCodeBehind(XamlProjectItem? xamlItem, Compilation compil
//optional default ctor
if (generateDefaultCtor)
{
sb.AppendLine($"\t\t/// <summary>");
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure there are automated tests in TestCases.Shared.Tests and TestCases.HostApp that verify CodeBehindGenerator emits the expected <summary> comments for generated types and constructors.

Copilot uses AI. Check for mistakes.

sb.AppendLine($"\t\t/// Creates a new {rootType}");
Copy link
Contributor

@dotMorten dotMorten Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should follow the standard doc convention for constructors, otherwise anyone having standard doc enforced in their code analyzers would just generate warnings here.

Suggested change
sb.AppendLine($"\t\t/// Creates a new {rootType}");
sb.AppendLine($"\t\t/// Initializes a new instance of the <see cref=\"{rootType}\" /> class.");

sb.AppendLine($"\t\t/// </summary>");
sb.AppendLine($"\t\t[global::System.CodeDom.Compiler.GeneratedCode(\"Microsoft.Maui.Controls.SourceGen\", \"1.0.0.0\")]");
sb.AppendLine($"\t\tpublic {rootType}()");
sb.AppendLine("\t\t{");
Expand Down