From 11aedc1da85da65d421dd607434078c52f65082c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Thu, 28 Nov 2024 14:49:19 +0100 Subject: [PATCH] Adjust xml docs --- ReactiveGenerator/ReactiveGenerator.cs | 53 +++++++++++++++++--------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/ReactiveGenerator/ReactiveGenerator.cs b/ReactiveGenerator/ReactiveGenerator.cs index d83fb5c..8f549cb 100644 --- a/ReactiveGenerator/ReactiveGenerator.cs +++ b/ReactiveGenerator/ReactiveGenerator.cs @@ -326,16 +326,25 @@ private static string GetAccessorAccessibility(IMethodSymbol? accessor) private static string GenerateINPCImplementation(INamedTypeSymbol classSymbol) { + // Helper method to format type names for XML docs + string FormatTypeNameForXmlDoc(ITypeSymbol type) + { + var minimalFormat = new SymbolDisplayFormat( + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes); + + return type.ToDisplayString(minimalFormat).Replace("<", "{").Replace(">", "}"); + } + var namespaceName = classSymbol.ContainingNamespace.IsGlobalNamespace ? null : classSymbol.ContainingNamespace.ToDisplayString(); var sb = new StringBuilder(); - sb.AppendLine("// "); sb.AppendLine("#nullable enable"); sb.AppendLine(); - sb.AppendLine("using System.ComponentModel;"); sb.AppendLine("using System.Runtime.CompilerServices;"); sb.AppendLine(); @@ -351,8 +360,10 @@ private static string GenerateINPCImplementation(INamedTypeSymbol classSymbol) // Add XML documentation comment if the class is public if (classSymbol.DeclaredAccessibility == Accessibility.Public) { + var xmlClassName = FormatTypeNameForXmlDoc(classSymbol); sb.AppendLine(" /// "); - sb.AppendLine($" /// A partial class for {classSymbol.Name} that implements INotifyPropertyChanged."); + sb.AppendLine( + $" /// A partial class implementation of for ."); sb.AppendLine(" /// "); } @@ -365,6 +376,7 @@ private static string GenerateINPCImplementation(INamedTypeSymbol classSymbol) sb.AppendLine(" /// "); sb.AppendLine(" /// Occurs when a property value changes."); sb.AppendLine(" /// "); + sb.AppendLine(" /// "); } sb.AppendLine(" public event PropertyChangedEventHandler? PropertyChanged;"); @@ -372,19 +384,21 @@ private static string GenerateINPCImplementation(INamedTypeSymbol classSymbol) // Add XML documentation comment for OnPropertyChanged method sb.AppendLine(" /// "); - sb.AppendLine(" /// Raises the PropertyChanged event."); + sb.AppendLine(" /// Raises the event."); sb.AppendLine(" /// "); sb.AppendLine(" /// The name of the property that changed."); - sb.AppendLine(" protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)"); + sb.AppendLine( + " protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)"); sb.AppendLine(" {"); sb.AppendLine(" PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// "); - sb.AppendLine(" /// Raises the PropertyChanged event."); + sb.AppendLine(" /// Raises the event."); sb.AppendLine(" /// "); - sb.AppendLine(" /// The PropertyChangedEventArgs."); + sb.AppendLine( + " /// The instance containing the event data."); sb.AppendLine(" protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)"); sb.AppendLine(" {"); sb.AppendLine(" PropertyChanged?.Invoke(this, args);"); @@ -417,7 +431,18 @@ private static string GenerateClassSource( var namespaceName = classSymbol.ContainingNamespace.IsGlobalNamespace ? null : classSymbol.ContainingNamespace.ToDisplayString(); + + // Helper method to format type names for XML docs + string FormatTypeNameForXmlDoc(ITypeSymbol type) + { + var minimalFormat = new SymbolDisplayFormat( + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes); + return type.ToDisplayString(minimalFormat).Replace("<", "{").Replace(">", "}"); + } + var sb = new StringBuilder(); sb.AppendLine("// "); @@ -448,8 +473,9 @@ private static string GenerateClassSource( // Add XML documentation comment if the class is public if (classSymbol.DeclaredAccessibility == Accessibility.Public) { + var xmlClassName = FormatTypeNameForXmlDoc(classSymbol); sb.AppendLine(" /// "); - sb.AppendLine($" /// A partial class for {classSymbol.Name}."); + sb.AppendLine($" /// A partial class implementation for ."); sb.AppendLine(" /// "); } @@ -521,17 +547,6 @@ private static string GenerateClassSource( // Generate properties if (typeProperties.Any()) { - // Add helper method to format type names for XML docs - string FormatTypeNameForXmlDoc(ITypeSymbol type) - { - var minimalFormat = new SymbolDisplayFormat( - typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, - genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, - miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes); - - return type.ToDisplayString(minimalFormat).Replace("<", "{").Replace(">", "}"); - } - var lastProperty = typeProperties.Last(); foreach (var property in typeProperties) {