Skip to content

Commit

Permalink
Adjust xml docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Nov 28, 2024
1 parent cb2ba3b commit 11aedc1
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions ReactiveGenerator/ReactiveGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("// <auto-generated/>");
sb.AppendLine("#nullable enable");
sb.AppendLine();

sb.AppendLine("using System.ComponentModel;");
sb.AppendLine("using System.Runtime.CompilerServices;");
sb.AppendLine();
Expand All @@ -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(" /// <summary>");
sb.AppendLine($" /// A partial class for {classSymbol.Name} that implements INotifyPropertyChanged.");
sb.AppendLine(
$" /// A partial class implementation of <see cref=\"INotifyPropertyChanged\"/> for <see cref=\"{xmlClassName}\"/>.");
sb.AppendLine(" /// </summary>");
}

Expand All @@ -365,26 +376,29 @@ private static string GenerateINPCImplementation(INamedTypeSymbol classSymbol)
sb.AppendLine(" /// <summary>");
sb.AppendLine(" /// Occurs when a property value changes.");
sb.AppendLine(" /// </summary>");
sb.AppendLine(" /// <seealso cref=\"INotifyPropertyChanged\"/>");
}

sb.AppendLine(" public event PropertyChangedEventHandler? PropertyChanged;");
sb.AppendLine();

// Add XML documentation comment for OnPropertyChanged method
sb.AppendLine(" /// <summary>");
sb.AppendLine(" /// Raises the PropertyChanged event.");
sb.AppendLine(" /// Raises the <see cref=\"PropertyChanged\"/> event.");
sb.AppendLine(" /// </summary>");
sb.AppendLine(" /// <param name=\"propertyName\">The name of the property that changed.</param>");
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(" /// <summary>");
sb.AppendLine(" /// Raises the PropertyChanged event.");
sb.AppendLine(" /// Raises the <see cref=\"PropertyChanged\"/> event.");
sb.AppendLine(" /// </summary>");
sb.AppendLine(" /// <param name=\"args\">The PropertyChangedEventArgs.</param>");
sb.AppendLine(
" /// <param name=\"args\">The <see cref=\"PropertyChangedEventArgs\"/> instance containing the event data.</param>");
sb.AppendLine(" protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)");
sb.AppendLine(" {");
sb.AppendLine(" PropertyChanged?.Invoke(this, args);");
Expand Down Expand Up @@ -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("// <auto-generated/>");
Expand Down Expand Up @@ -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(" /// <summary>");
sb.AppendLine($" /// A partial class for {classSymbol.Name}.");
sb.AppendLine($" /// A partial class implementation for <see cref=\"{xmlClassName}\"/>.");
sb.AppendLine(" /// </summary>");
}

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 11aedc1

Please sign in to comment.