diff --git a/.editorconfig b/.editorconfig index dba4fcb..d8860dc 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,7 +7,7 @@ [*] indent_style = space -[*.{csproj,xml}] +[*.{csproj,xml,runsettings}] indent_size = 2 # Code files diff --git a/LivingDocumentation.runsettings b/LivingDocumentation.runsettings index e5160b3..c738b52 100644 --- a/LivingDocumentation.runsettings +++ b/LivingDocumentation.runsettings @@ -7,6 +7,20 @@ lcov,cobertura + + + + + + .*\.dll$ + + + .*\.Tests\.dll$ + + + + + diff --git a/samples/LivingDocumentation.eShopOnContainers/AsciiDocRenderer.cs b/samples/LivingDocumentation.eShopOnContainers/AsciiDocRenderer.cs index 25f4e8b..efc944a 100644 --- a/samples/LivingDocumentation.eShopOnContainers/AsciiDocRenderer.cs +++ b/samples/LivingDocumentation.eShopOnContainers/AsciiDocRenderer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -8,21 +8,10 @@ namespace LivingDocumentation.eShopOnContainers { - public class AsciiDocRenderer + public partial class AsciiDocRenderer(IReadOnlyList types, IReadOnlyDictionary aggregateFiles, IReadOnlyDictionary commandHandlerFiles, IReadOnlyDictionary eventHandlerFiles) { - private readonly IReadOnlyList types; - private readonly IReadOnlyDictionary aggregateFiles; - private readonly IReadOnlyDictionary commandHandlerFiles; - private readonly IReadOnlyDictionary eventHandlerFiles; - private static readonly Regex replaceTypeSuffix = new Regex("(?:(?:Command|(?:Domain|Integration)Event))(?:Handler)?$", RegexOptions.CultureInvariant); - - public AsciiDocRenderer(IReadOnlyList types, IReadOnlyDictionary aggregateFiles, IReadOnlyDictionary commandHandlerFiles, IReadOnlyDictionary eventHandlerFiles) - { - this.types = types; - this.aggregateFiles = aggregateFiles; - this.commandHandlerFiles = commandHandlerFiles; - this.eventHandlerFiles = eventHandlerFiles; - } + [GeneratedRegex("(?:(?:Command|(?:Domain|Integration)Event))(?:Handler)?$", RegexOptions.CultureInvariant)] + private static partial Regex TypeSuffix(); public void Render() { @@ -47,7 +36,7 @@ private void RenderAggregates(StringBuilder stringBuilder) stringBuilder.AppendLine("== Aggregates"); stringBuilder.AppendLine("Aggregates in the eShop application."); - foreach (var (type, path) in this.aggregateFiles.Select(kv => (Type: this.types.FirstOrDefault(kv.Key), Path: kv.Value)).OrderBy(t => t.Type.Name)) + foreach (var (type, path) in aggregateFiles.Select(kv => (Type: types.FirstOrDefault(kv.Key), Path: kv.Value)).OrderBy(t => t.Type.Name)) { stringBuilder.AppendLine(); stringBuilder.AppendLine($"// tag::aggregate-{StripTypeSuffix(type.Name).ToLowerInvariant()}[]"); @@ -72,7 +61,7 @@ private void RenderCommands(StringBuilder stringBuilder) stringBuilder.AppendLine("== Commands"); stringBuilder.AppendLine("Commands in the eShop application."); - foreach (var type in this.types.Where(t => t.IsCommand() && !t.FullName.IsGeneric()).OrderBy(t => t.Name)) + foreach (var type in types.Where(t => t.IsCommand() && !t.FullName.IsGeneric()).OrderBy(t => t.Name)) { stringBuilder.AppendLine(); stringBuilder.AppendLine($"=== {FormatTechnicalName(type.Name)}"); @@ -108,7 +97,7 @@ private void RenderCommandHandlers(StringBuilder stringBuilder) stringBuilder.AppendLine("== Command Handlers"); stringBuilder.AppendLine("Command handlers in the eShop application."); - foreach (var (type, path) in this.commandHandlerFiles.Select(kv => (Type: this.types.FirstOrDefault(kv.Key), Path: kv.Value)).OrderBy(t => t.Type.Name)) + foreach (var (type, path) in commandHandlerFiles.Select(kv => (Type: types.FirstOrDefault(kv.Key), Path: kv.Value)).OrderBy(t => t.Type.Name)) { stringBuilder.AppendLine(); stringBuilder.AppendLine($"// tag::commandhandler-{StripTypeSuffix(type.Name).ToLowerInvariant()}[]"); @@ -140,7 +129,7 @@ private void RenderDomainEvents(StringBuilder stringBuilder) stringBuilder.AppendLine("== Domain Events"); stringBuilder.AppendLine("Domain events in the eShop application."); - foreach (var type in this.types.Where(t => t.IsDomainEvent()).OrderBy(t => t.Name)) + foreach (var type in types.Where(t => t.IsDomainEvent()).OrderBy(t => t.Name)) { stringBuilder.AppendLine(); stringBuilder.AppendLine($"=== {FormatTechnicalName(type.Name)}"); @@ -176,7 +165,7 @@ private void RenderDomainEventHandlers(StringBuilder stringBuilder) stringBuilder.AppendLine("== Domain Event Handlers"); stringBuilder.AppendLine("Domain event handlers in the eShop application."); - foreach (var (type, path) in this.eventHandlerFiles.Select(kv => (Type: this.types.FirstOrDefault(kv.Key), Path: kv.Value)).OrderBy(t => t.Type.Name)) + foreach (var (type, path) in eventHandlerFiles.Select(kv => (Type: types.FirstOrDefault(kv.Key), Path: kv.Value)).OrderBy(t => t.Type.Name)) { stringBuilder.AppendLine(); stringBuilder.AppendLine($"// tag::domaineventhandler-{StripTypeSuffix(type.Name).ToLowerInvariant()}[]"); @@ -207,7 +196,7 @@ private void RenderIntegrationEvents(StringBuilder stringBuilder) stringBuilder.AppendLine("== Integration Events"); stringBuilder.AppendLine("Integration events in the eShop application."); - foreach (var type in this.types.Where(t => t.IsIntegrationEvent() && t.FullName.StartsWith("Ordering.API", StringComparison.Ordinal)).OrderBy(t => t.Name)) + foreach (var type in types.Where(t => t.IsIntegrationEvent() && t.FullName.StartsWith("Ordering.API", StringComparison.Ordinal)).OrderBy(t => t.Name)) { stringBuilder.AppendLine(); stringBuilder.AppendLine($"=== {FormatTechnicalName(type.Name)}"); @@ -254,7 +243,7 @@ private static void RenderFileHeader(StringBuilder stringBuilder) private static string StripTypeSuffix(string name) { - return replaceTypeSuffix.Replace(name, string.Empty); + return TypeSuffix().Replace(name, string.Empty); } private static string FormatTechnicalName(string name) diff --git a/samples/LivingDocumentation.eShopOnContainers/LivingDocumentation.Sample.eShopOnContainers.csproj b/samples/LivingDocumentation.eShopOnContainers/LivingDocumentation.Sample.eShopOnContainers.csproj index 7f0ed24..dcfd681 100644 --- a/samples/LivingDocumentation.eShopOnContainers/LivingDocumentation.Sample.eShopOnContainers.csproj +++ b/samples/LivingDocumentation.eShopOnContainers/LivingDocumentation.Sample.eShopOnContainers.csproj @@ -2,14 +2,14 @@ Exe - net7.0 + net8.0 latest false - + diff --git a/samples/LivingDocumentation.eShopOnContainers/eShopOnContainerExtensions.cs b/samples/LivingDocumentation.eShopOnContainers/eShopOnContainerExtensions.cs index 07639e1..6711bd7 100644 --- a/samples/LivingDocumentation.eShopOnContainers/eShopOnContainerExtensions.cs +++ b/samples/LivingDocumentation.eShopOnContainers/eShopOnContainerExtensions.cs @@ -1,4 +1,4 @@ -using PlantUml.Builder; +using PlantUml.Builder; using System; using System.Linq; @@ -36,27 +36,27 @@ public static string FormatForDiagram(this string name) { if (name.EndsWith(IntegrationEvent)) { - return name.Substring(0, name.Length - IntegrationEvent.Length); + return name[..^IntegrationEvent.Length]; } if (name.EndsWith(DomainEvent)) { - return name.Substring(0, name.Length - DomainEvent.Length); + return name[..^DomainEvent.Length]; } if (name.EndsWith(Command)) { - return name.Substring(0, name.Length - Command.Length); + return name[..^Command.Length]; } if (name.EndsWith(DomainEventHandler)) { - return name.Substring(0, name.Length - DomainEventHandler.Length) + "\\n//<>//"; + return name[..^DomainEventHandler.Length] + "\\n//<>//"; } if (name.EndsWith(CommandHandler)) { - return name.Substring(0, name.Length - CommandHandler.Length) + "\\n//<>//"; + return name[..^CommandHandler.Length] + "\\n//<>//"; } return name; diff --git a/src/LivingDocumentation.Abstractions/LivingDocumentation.Abstractions.csproj b/src/LivingDocumentation.Abstractions/LivingDocumentation.Abstractions.csproj index 26e6423..33d6a6f 100644 --- a/src/LivingDocumentation.Abstractions/LivingDocumentation.Abstractions.csproj +++ b/src/LivingDocumentation.Abstractions/LivingDocumentation.Abstractions.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 LivingDocumentation @@ -27,8 +27,8 @@ - - + + diff --git a/src/LivingDocumentation.Abstractions/Statement.cs b/src/LivingDocumentation.Abstractions/Statement.cs index 94ba604..428acdd 100644 --- a/src/LivingDocumentation.Abstractions/Statement.cs +++ b/src/LivingDocumentation.Abstractions/Statement.cs @@ -3,7 +3,7 @@ namespace LivingDocumentation; public abstract class Statement { [JsonProperty(ItemTypeNameHandling = TypeNameHandling.Objects)] - public virtual List Statements { get; } = new(); + public virtual List Statements { get; } = []; [JsonIgnore] public object? Parent diff --git a/src/LivingDocumentation.Analyzer/Analyzers/BranchingAnalyzer.cs b/src/LivingDocumentation.Analyzer/Analyzers/BranchingAnalyzer.cs index 40be996..168e475 100644 --- a/src/LivingDocumentation.Analyzer/Analyzers/BranchingAnalyzer.cs +++ b/src/LivingDocumentation.Analyzer/Analyzers/BranchingAnalyzer.cs @@ -1,27 +1,18 @@ namespace LivingDocumentation; -internal class BranchingAnalyzer : CSharpSyntaxWalker +internal class BranchingAnalyzer(SemanticModel semanticModel, List statements) : CSharpSyntaxWalker { - private readonly SemanticModel semanticModel; - private readonly List statements; - - public BranchingAnalyzer(in SemanticModel semanticModel, List statements) - { - this.semanticModel = semanticModel; - this.statements = statements; - } - public override void VisitIfStatement(IfStatementSyntax node) { var ifStatement = new If(); - this.statements.Add(ifStatement); + statements.Add(ifStatement); var ifSection = new IfElseSection(); ifStatement.Sections.Add(ifSection); ifSection.Condition = node.Condition.ToString(); - var ifInvocationAnalyzer = new InvocationsAnalyzer(this.semanticModel, ifSection.Statements); + var ifInvocationAnalyzer = new InvocationsAnalyzer(semanticModel, ifSection.Statements); ifInvocationAnalyzer.Visit(node.Statement); var elseNode = node.Else; @@ -30,7 +21,7 @@ public override void VisitIfStatement(IfStatementSyntax node) var section = new IfElseSection(); ifStatement.Sections.Add(section); - var elseInvocationAnalyzer = new InvocationsAnalyzer(this.semanticModel, section.Statements); + var elseInvocationAnalyzer = new InvocationsAnalyzer(semanticModel, section.Statements); elseInvocationAnalyzer.Visit(elseNode.Statement); if (elseNode.Statement.IsKind(SyntaxKind.IfStatement)) @@ -50,7 +41,7 @@ public override void VisitIfStatement(IfStatementSyntax node) public override void VisitSwitchStatement(SwitchStatementSyntax node) { var switchStatement = new Switch(); - this.statements.Add(switchStatement); + statements.Add(switchStatement); switchStatement.Expression = node.Expression.ToString(); @@ -61,7 +52,7 @@ public override void VisitSwitchStatement(SwitchStatementSyntax node) switchSection.Labels.AddRange(section.Labels.Select(l => Label(l))); - var invocationAnalyzer = new InvocationsAnalyzer(this.semanticModel, switchSection.Statements); + var invocationAnalyzer = new InvocationsAnalyzer(semanticModel, switchSection.Statements); invocationAnalyzer.Visit(section); } } diff --git a/src/LivingDocumentation.Analyzer/Analyzers/InvocationsAnalyzer.cs b/src/LivingDocumentation.Analyzer/Analyzers/InvocationsAnalyzer.cs index 44a7c6f..82c2798 100644 --- a/src/LivingDocumentation.Analyzer/Analyzers/InvocationsAnalyzer.cs +++ b/src/LivingDocumentation.Analyzer/Analyzers/InvocationsAnalyzer.cs @@ -1,28 +1,19 @@ namespace LivingDocumentation; -internal class InvocationsAnalyzer : CSharpSyntaxWalker +internal class InvocationsAnalyzer(SemanticModel semanticModel, List statements) : CSharpSyntaxWalker { - private readonly SemanticModel semanticModel; - private readonly List statements; - - public InvocationsAnalyzer(in SemanticModel semanticModel, List statements) - { - this.semanticModel = semanticModel; - this.statements = statements; - } - public override void VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) { - string containingType = this.semanticModel.GetTypeDisplayString(node); + string containingType = semanticModel.GetTypeDisplayString(node); var invocation = new InvocationDescription(containingType, node.Type.ToString()); - this.statements.Add(invocation); + statements.Add(invocation); if (node.ArgumentList != null) { foreach (var argument in node.ArgumentList.Arguments) { - var argumentDescription = new ArgumentDescription(this.semanticModel.GetTypeDisplayString(argument.Expression), argument.Expression.ToString()); + var argumentDescription = new ArgumentDescription(semanticModel.GetTypeDisplayString(argument.Expression), argument.Expression.ToString()); invocation.Arguments.Add(argumentDescription); } } @@ -31,7 +22,7 @@ public override void VisitObjectCreationExpression(ObjectCreationExpressionSynta { foreach (var expression in node.Initializer.Expressions) { - var argumentDescription = new ArgumentDescription(this.semanticModel.GetTypeDisplayString(expression), expression.ToString()); + var argumentDescription = new ArgumentDescription(semanticModel.GetTypeDisplayString(expression), expression.ToString()); invocation.Arguments.Add(argumentDescription); } } @@ -41,19 +32,19 @@ public override void VisitObjectCreationExpression(ObjectCreationExpressionSynta public override void VisitSwitchStatement(SwitchStatementSyntax node) { - var branchingAnalyzer = new BranchingAnalyzer(this.semanticModel, this.statements); + var branchingAnalyzer = new BranchingAnalyzer(semanticModel, statements); branchingAnalyzer.Visit(node); } public override void VisitIfStatement(IfStatementSyntax node) { - var branchingAnalyzer = new BranchingAnalyzer(this.semanticModel, this.statements); + var branchingAnalyzer = new BranchingAnalyzer(semanticModel, statements); branchingAnalyzer.Visit(node); } public override void VisitForEachStatement(ForEachStatementSyntax node) { - var loopingAnalyzer = new LoopingAnalyzer(this.semanticModel, this.statements); + var loopingAnalyzer = new LoopingAnalyzer(semanticModel, statements); loopingAnalyzer.Visit(node); } @@ -61,23 +52,23 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node) { var expression = this.GetExpressionWithSymbol(node); - if (Program.RuntimeOptions.VerboseOutput && this.semanticModel.GetSymbolInfo(expression).Symbol == null) + if (Program.RuntimeOptions.VerboseOutput && semanticModel.GetSymbolInfo(expression).Symbol == null) { Console.WriteLine("WARN: Could not resolve type of invocation of the following block:"); Console.WriteLine(node.ToFullString()); return; } - if (this.semanticModel.GetConstantValue(node).HasValue && string.Equals((node.Expression as IdentifierNameSyntax)?.Identifier.ValueText, "nameof", StringComparison.Ordinal)) + if (semanticModel.GetConstantValue(node).HasValue && string.Equals((node.Expression as IdentifierNameSyntax)?.Identifier.ValueText, "nameof", StringComparison.Ordinal)) { // nameof is compiler sugar, and is actually a method we are not interrested in return; } - var containingType = this.semanticModel.GetSymbolInfo(expression).Symbol?.ContainingSymbol.ToDisplayString(); + var containingType = semanticModel.GetSymbolInfo(expression).Symbol?.ContainingSymbol.ToDisplayString(); if (containingType == null) { - containingType = this.semanticModel.GetSymbolInfo(expression).CandidateSymbols.FirstOrDefault()?.ContainingSymbol.ToDisplayString(); + containingType = semanticModel.GetSymbolInfo(expression).CandidateSymbols.FirstOrDefault()?.ContainingSymbol.ToDisplayString(); } var methodName = string.Empty; @@ -93,13 +84,13 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node) } var invocation = new InvocationDescription(containingType, methodName); - this.statements.Add(invocation); + statements.Add(invocation); foreach (var argument in node.ArgumentList.Arguments) { - var value = argument.Expression.ResolveValue(this.semanticModel); + var value = argument.Expression.ResolveValue(semanticModel); - var argumentDescription = new ArgumentDescription(this.semanticModel.GetTypeDisplayString(argument.Expression), value); + var argumentDescription = new ArgumentDescription(semanticModel.GetTypeDisplayString(argument.Expression), value); invocation.Arguments.Add(argumentDescription); } @@ -110,12 +101,12 @@ private ExpressionSyntax GetExpressionWithSymbol(InvocationExpressionSyntax node { var expression = node.Expression; - if (this.semanticModel.GetSymbolInfo(expression).Symbol == null) + if (semanticModel.GetSymbolInfo(expression).Symbol == null) { // This might be part of a chain of extention methods (f.e. Fluent API's), the symbols are only available at the beginning of the chain. var pNode = (SyntaxNode)node; - while (pNode != null && (pNode is not InvocationExpressionSyntax || (pNode is InvocationExpressionSyntax && (this.semanticModel.GetTypeInfo(pNode).Type?.Kind == SymbolKind.ErrorType || this.semanticModel.GetSymbolInfo(expression).Symbol == null)))) + while (pNode != null && (pNode is not InvocationExpressionSyntax || (pNode is InvocationExpressionSyntax && (semanticModel.GetTypeInfo(pNode).Type?.Kind == SymbolKind.ErrorType || semanticModel.GetSymbolInfo(expression).Symbol == null)))) { pNode = pNode.Parent; @@ -131,16 +122,16 @@ private ExpressionSyntax GetExpressionWithSymbol(InvocationExpressionSyntax node public override void VisitReturnStatement(ReturnStatementSyntax node) { - var returnDescription = new ReturnDescription(node.Expression?.ResolveValue(this.semanticModel) ?? string.Empty); - this.statements.Add(returnDescription); + var returnDescription = new ReturnDescription(node.Expression?.ResolveValue(semanticModel) ?? string.Empty); + statements.Add(returnDescription); base.VisitReturnStatement(node); } public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node) { - var returnDescription = new ReturnDescription(node.Expression.ResolveValue(this.semanticModel)); - this.statements.Add(returnDescription); + var returnDescription = new ReturnDescription(node.Expression.ResolveValue(semanticModel)); + statements.Add(returnDescription); base.VisitArrowExpressionClause(node); } @@ -148,7 +139,7 @@ public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node public override void VisitAssignmentExpression(AssignmentExpressionSyntax node) { var assignmentDescription = new AssignmentDescription(node.Left.ToString(), node.OperatorToken.Text, node.Right.ToString()); - this.statements.Add(assignmentDescription); + statements.Add(assignmentDescription); base.VisitAssignmentExpression(node); } diff --git a/src/LivingDocumentation.Analyzer/Analyzers/LoopingAnalyzer.cs b/src/LivingDocumentation.Analyzer/Analyzers/LoopingAnalyzer.cs index c09c0c3..8a430ee 100644 --- a/src/LivingDocumentation.Analyzer/Analyzers/LoopingAnalyzer.cs +++ b/src/LivingDocumentation.Analyzer/Analyzers/LoopingAnalyzer.cs @@ -1,24 +1,15 @@ namespace LivingDocumentation; -internal class LoopingAnalyzer : CSharpSyntaxWalker +internal class LoopingAnalyzer(SemanticModel semanticModel, List statements) : CSharpSyntaxWalker { - private readonly SemanticModel semanticModel; - private readonly List statements; - - public LoopingAnalyzer(in SemanticModel semanticModel, List statements) - { - this.semanticModel = semanticModel; - this.statements = statements; - } - public override void VisitForEachStatement(ForEachStatementSyntax node) { var forEachStatement = new ForEach(); - this.statements.Add(forEachStatement); + statements.Add(forEachStatement); forEachStatement.Expression = $"{node.Identifier} in {node.Expression}"; - var invocationAnalyzer = new InvocationsAnalyzer(this.semanticModel, forEachStatement.Statements); + var invocationAnalyzer = new InvocationsAnalyzer(semanticModel, forEachStatement.Statements); invocationAnalyzer.Visit(node.Statement); } } diff --git a/src/LivingDocumentation.Analyzer/Analyzers/SourceAnalyzer.cs b/src/LivingDocumentation.Analyzer/Analyzers/SourceAnalyzer.cs index 80097dc..58fb3ac 100644 --- a/src/LivingDocumentation.Analyzer/Analyzers/SourceAnalyzer.cs +++ b/src/LivingDocumentation.Analyzer/Analyzers/SourceAnalyzer.cs @@ -1,18 +1,9 @@ namespace LivingDocumentation; -public class SourceAnalyzer : CSharpSyntaxWalker +public class SourceAnalyzer(SemanticModel semanticModel, List types) : CSharpSyntaxWalker { - private readonly SemanticModel semanticModel; - private readonly List types; - private TypeDescription? currentType = null; - public SourceAnalyzer(in SemanticModel semanticModel, List types) - { - this.types = types; - this.semanticModel = semanticModel; - } - public override void VisitClassDeclaration(ClassDeclarationSyntax node) { if (this.ProcessedEmbeddedType(node)) return; @@ -22,7 +13,6 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node) base.VisitClassDeclaration(node); } -#if NET6_0_OR_GREATER public override void VisitRecordDeclaration(RecordDeclarationSyntax node) { if (this.ProcessedEmbeddedType(node)) return; @@ -38,7 +28,7 @@ public override void VisitRecordDeclaration(RecordDeclarationSyntax node) base.VisitRecordDeclaration(node); // Check for parts that are generated and not declared by the author - var symbol = this.semanticModel.GetDeclaredSymbol(node); + var symbol = semanticModel.GetDeclaredSymbol(node); if (symbol != null) { foreach (var constructor in symbol.Constructors) @@ -82,7 +72,6 @@ public override void VisitRecordDeclaration(RecordDeclarationSyntax node) } } } -#endif public override void VisitEnumDeclaration(EnumDeclarationSyntax node) { @@ -117,14 +106,14 @@ public override void VisitFieldDeclaration(FieldDeclarationSyntax node) foreach (var variable in node.Declaration.Variables) { - var fieldDescription = new FieldDescription(this.semanticModel.GetTypeDisplayString(node.Declaration.Type), variable.Identifier.ValueText); + var fieldDescription = new FieldDescription(semanticModel.GetTypeDisplayString(node.Declaration.Type), variable.Identifier.ValueText); this.currentType.AddMember(fieldDescription); fieldDescription.Modifiers |= ParseModifiers(node.Modifiers); this.EnsureMemberDefaultAccessModifier(fieldDescription); this.ExtractAttributes(node.AttributeLists, fieldDescription.Attributes); - fieldDescription.Initializer = variable.Initializer?.Value.ResolveValue(this.semanticModel); + fieldDescription.Initializer = variable.Initializer?.Value.ResolveValue(semanticModel); fieldDescription.DocumentationComments = this.ExtractDocumentation(variable); } @@ -137,14 +126,14 @@ public override void VisitEventFieldDeclaration(EventFieldDeclarationSyntax node foreach (var variable in node.Declaration.Variables) { - var eventDescription = new EventDescription(this.semanticModel.GetTypeDisplayString(node.Declaration.Type), variable.Identifier.ValueText); + var eventDescription = new EventDescription(semanticModel.GetTypeDisplayString(node.Declaration.Type), variable.Identifier.ValueText); this.currentType.AddMember(eventDescription); eventDescription.Modifiers |= ParseModifiers(node.Modifiers); this.EnsureMemberDefaultAccessModifier(eventDescription); this.ExtractAttributes(node.AttributeLists, eventDescription.Attributes); - eventDescription.Initializer = variable.Initializer?.Value.ResolveValue(this.semanticModel); + eventDescription.Initializer = variable.Initializer?.Value.ResolveValue(semanticModel); eventDescription.DocumentationComments = this.ExtractDocumentation(variable); } @@ -155,14 +144,14 @@ public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) { if (this.currentType is null) return; - var propertyDescription = new PropertyDescription(this.semanticModel.GetTypeDisplayString(node.Type), node.Identifier.ToString()); + var propertyDescription = new PropertyDescription(semanticModel.GetTypeDisplayString(node.Type), node.Identifier.ToString()); this.currentType.AddMember(propertyDescription); propertyDescription.Modifiers |= ParseModifiers(node.Modifiers); this.EnsureMemberDefaultAccessModifier(propertyDescription); this.ExtractAttributes(node.AttributeLists, propertyDescription.Attributes); - propertyDescription.Initializer = node.Initializer?.Value.ResolveValue(this.semanticModel); + propertyDescription.Initializer = node.Initializer?.Value.ResolveValue(semanticModel); propertyDescription.DocumentationComments = this.ExtractDocumentation(node); base.VisitPropertyDeclaration(node); @@ -197,7 +186,7 @@ public override void VisitMethodDeclaration(MethodDeclarationSyntax node) { if (this.currentType is null) return; - var methodDescription = new MethodDescription(this.semanticModel.GetTypeInfo(node.ReturnType).Type?.ToDisplayString(), node.Identifier.ToString()); + var methodDescription = new MethodDescription(semanticModel.GetTypeInfo(node.ReturnType).Type?.ToDisplayString(), node.Identifier.ToString()); this.currentType.AddMember(methodDescription); this.ExtractBaseMethodDeclaration(node, methodDescription); @@ -207,20 +196,20 @@ public override void VisitMethodDeclaration(MethodDeclarationSyntax node) private void ExtractBaseTypeDeclaration(TypeType type, BaseTypeDeclarationSyntax node) { - var currentType = new TypeDescription(type, this.semanticModel.GetDeclaredSymbol(node)?.ToDisplayString()); - if (!this.types.Contains(currentType)) + var currentType = new TypeDescription(type, semanticModel.GetDeclaredSymbol(node)?.ToDisplayString()); + if (!types.Contains(currentType)) { - this.types.Add(currentType); + types.Add(currentType); this.currentType = currentType; } else { - this.currentType = this.types.First(t => string.Equals(t.FullName, currentType.FullName, StringComparison.Ordinal)); + this.currentType = types.First(t => string.Equals(t.FullName, currentType.FullName, StringComparison.Ordinal)); } if (node.BaseList != null) { - this.currentType.BaseTypes.AddRange(node.BaseList.Types.Select(t => this.semanticModel.GetTypeDisplayString(t.Type))); + this.currentType.BaseTypes.AddRange(node.BaseList.Types.Select(t => semanticModel.GetTypeDisplayString(t.Type))); } this.currentType.Modifiers |= ParseModifiers(node.Modifiers); @@ -269,7 +258,7 @@ private bool ProcessedEmbeddedType(SyntaxNode node) return false; } - var embeddedAnalyzer = new SourceAnalyzer(this.semanticModel, this.types); + var embeddedAnalyzer = new SourceAnalyzer(semanticModel, types); embeddedAnalyzer.Visit(node); return true; @@ -284,16 +273,16 @@ private void ExtractAttributes(SyntaxList attributes, List< foreach (var attribute in attributes.SelectMany(a => a.Attributes)) { - var attributeDescription = new AttributeDescription(this.semanticModel.GetTypeDisplayString(attribute), attribute.Name.ToString()); + var attributeDescription = new AttributeDescription(semanticModel.GetTypeDisplayString(attribute), attribute.Name.ToString()); attributeDescriptions.Add(attributeDescription); if (attribute.ArgumentList != null) { foreach (var argument in attribute.ArgumentList.Arguments) { - var value = argument.Expression!.ResolveValue(this.semanticModel); + var value = argument.Expression!.ResolveValue(semanticModel); - var argumentDescription = new AttributeArgumentDescription(argument.NameEquals?.Name.ToString() ?? argument.Expression.ResolveValue(this.semanticModel), this.semanticModel.GetTypeDisplayString(argument.Expression!), value); + var argumentDescription = new AttributeArgumentDescription(argument.NameEquals?.Name.ToString() ?? argument.Expression.ResolveValue(semanticModel), semanticModel.GetTypeDisplayString(argument.Expression!), value); attributeDescription.Arguments.Add(argumentDescription); } } @@ -302,7 +291,7 @@ private void ExtractAttributes(SyntaxList attributes, List< private DocumentationCommentsDescription? ExtractDocumentation(SyntaxNode node) { - return DocumentationCommentsDescription.Parse(this.semanticModel.GetDeclaredSymbol(node)?.GetDocumentationCommentXml()); + return DocumentationCommentsDescription.Parse(semanticModel.GetDeclaredSymbol(node)?.GetDocumentationCommentXml()); } private void ExtractBaseMethodDeclaration(BaseMethodDeclarationSyntax node, IHaveAMethodBody method) @@ -315,14 +304,14 @@ private void ExtractBaseMethodDeclaration(BaseMethodDeclarationSyntax node, IHav foreach (var parameter in node.ParameterList.Parameters) { - var parameterDescription = new ParameterDescription(this.semanticModel.GetTypeDisplayString(parameter.Type!), parameter.Identifier.ToString()); + var parameterDescription = new ParameterDescription(semanticModel.GetTypeDisplayString(parameter.Type!), parameter.Identifier.ToString()); method.Parameters.Add(parameterDescription); parameterDescription.HasDefaultValue = parameter.Default != null; this.ExtractAttributes(parameter.AttributeLists, parameterDescription.Attributes); } - var invocationAnalyzer = new InvocationsAnalyzer(this.semanticModel, method.Statements); + var invocationAnalyzer = new InvocationsAnalyzer(semanticModel, method.Statements); invocationAnalyzer.Visit((SyntaxNode?)node.Body ?? node.ExpressionBody); } diff --git a/src/LivingDocumentation.Analyzer/Extensions/ExpressionSyntaxExtensions.cs b/src/LivingDocumentation.Analyzer/Extensions/ExpressionSyntaxExtensions.cs index 539dd5d..329f41f 100644 --- a/src/LivingDocumentation.Analyzer/Extensions/ExpressionSyntaxExtensions.cs +++ b/src/LivingDocumentation.Analyzer/Extensions/ExpressionSyntaxExtensions.cs @@ -25,7 +25,7 @@ private static string FormatObjectCreation(ObjectCreationExpressionSyntax object var initializer = objectCreation.Initializer; if (initializer is not null) { - var expressions = new SeparatedSyntaxList(); + var expressions = new SeparatedSyntaxList(); foreach (var expression in initializer.Expressions) { @@ -46,7 +46,7 @@ private static string FormatArrayCreation(ArrayCreationExpressionSyntax arrayCre var initializer = arrayCreation.Initializer; if (initializer is not null) { - var expressions = new SeparatedSyntaxList(); + var expressions = new SeparatedSyntaxList(); foreach (var expression in initializer.Expressions) { diff --git a/src/LivingDocumentation.Analyzer/LivingDocumentation.Analyzer.csproj b/src/LivingDocumentation.Analyzer/LivingDocumentation.Analyzer.csproj index 6f8d799..a1b3d0f 100644 --- a/src/LivingDocumentation.Analyzer/LivingDocumentation.Analyzer.csproj +++ b/src/LivingDocumentation.Analyzer/LivingDocumentation.Analyzer.csproj @@ -2,7 +2,7 @@ Exe - net6.0;net7.0 + net8.0 LivingDocumentation.Analyzer LivingDocumentation.Analyzer @@ -44,10 +44,10 @@ - + - - + + diff --git a/src/LivingDocumentation.Analyzer/Program.cs b/src/LivingDocumentation.Analyzer/Program.cs index ec8b3cb..2022f3c 100644 --- a/src/LivingDocumentation.Analyzer/Program.cs +++ b/src/LivingDocumentation.Analyzer/Program.cs @@ -47,6 +47,7 @@ private static async Task RunApplicationAsync(Options options) if (!options.Quiet) { Console.WriteLine($"Living Documentation Analysis output generated in {stopwatch.ElapsedMilliseconds}ms at {options.OutputPath}"); + Console.WriteLine($"{types.Count} types found"); } } diff --git a/src/LivingDocumentation.Descriptions/ArgumentDescription.cs b/src/LivingDocumentation.Descriptions/ArgumentDescription.cs index 2e21b0c..7ce1a77 100644 --- a/src/LivingDocumentation.Descriptions/ArgumentDescription.cs +++ b/src/LivingDocumentation.Descriptions/ArgumentDescription.cs @@ -1,15 +1,9 @@ namespace LivingDocumentation; [DebuggerDisplay("Argument {Text} ({Type,nq})")] -public class ArgumentDescription +public class ArgumentDescription(string type, string text) { - public string Type { get; } + public string Type { get; } = type ?? throw new ArgumentNullException(nameof(type)); - public string Text { get; } - - public ArgumentDescription(string type, string text) - { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.Text = text ?? throw new ArgumentNullException(nameof(text)); - } + public string Text { get; } = text ?? throw new ArgumentNullException(nameof(text)); } diff --git a/src/LivingDocumentation.Descriptions/AssignmentDescription.cs b/src/LivingDocumentation.Descriptions/AssignmentDescription.cs index 492fe0e..90ef015 100644 --- a/src/LivingDocumentation.Descriptions/AssignmentDescription.cs +++ b/src/LivingDocumentation.Descriptions/AssignmentDescription.cs @@ -1,18 +1,11 @@ namespace LivingDocumentation; [DebuggerDisplay("Assignment \"{Left,nq} {Operator,nq} {Right,nq}\"")] -public class AssignmentDescription : Statement +public class AssignmentDescription(string left, string @operator, string right) : Statement { - public string Left { get; } + public string Left { get; } = left ?? throw new ArgumentNullException(nameof(left)); - public string Operator { get; } + public string Operator { get; } = @operator ?? throw new ArgumentNullException(nameof(@operator)); - public string Right { get; } - - public AssignmentDescription(string left, string @operator, string right) - { - this.Left = left ?? throw new ArgumentNullException(nameof(left)); - this.Operator = @operator ?? throw new ArgumentNullException(nameof(@operator)); - this.Right = right ?? throw new ArgumentNullException(nameof(right)); - } + public string Right { get; } = right ?? throw new ArgumentNullException(nameof(right)); } diff --git a/src/LivingDocumentation.Descriptions/AttributeArgumentDescription.cs b/src/LivingDocumentation.Descriptions/AttributeArgumentDescription.cs index 79caf6d..2a34d1b 100644 --- a/src/LivingDocumentation.Descriptions/AttributeArgumentDescription.cs +++ b/src/LivingDocumentation.Descriptions/AttributeArgumentDescription.cs @@ -1,18 +1,11 @@ namespace LivingDocumentation; [DebuggerDisplay("AttributeArgument {Name} {Type} {Value}")] -public class AttributeArgumentDescription : IAttributeArgumentDescription +public class AttributeArgumentDescription(string? name, string? type, string? value) : IAttributeArgumentDescription { - public string Name { get; } + public string Name { get; } = name ?? throw new ArgumentNullException("name"); - public string Type { get; } + public string Type { get; } = type ?? throw new ArgumentNullException("type"); - public string Value { get; } - - public AttributeArgumentDescription(string? name, string? type, string? value) - { - this.Name = name ?? throw new ArgumentNullException("name"); - this.Type = type ?? throw new ArgumentNullException("type"); - this.Value = value ?? throw new ArgumentNullException("value"); - } + public string Value { get; } = value ?? throw new ArgumentNullException("value"); } diff --git a/src/LivingDocumentation.Descriptions/AttributeDescription.cs b/src/LivingDocumentation.Descriptions/AttributeDescription.cs index 41787f3..000da71 100644 --- a/src/LivingDocumentation.Descriptions/AttributeDescription.cs +++ b/src/LivingDocumentation.Descriptions/AttributeDescription.cs @@ -1,19 +1,13 @@ namespace LivingDocumentation; [DebuggerDisplay("Attribute {Type} {Name}")] -public class AttributeDescription : IAttributeDescription +public class AttributeDescription(string? type, string? name) : IAttributeDescription { - public string Type { get; } + public string Type { get; } = type ?? throw new ArgumentNullException(nameof(type)); - public string Name { get; } + public string Name { get; } = name ?? throw new ArgumentNullException(nameof(name)); [JsonProperty(ItemTypeNameHandling = TypeNameHandling.None)] [JsonConverter(typeof(ConcreteTypeConverter>))] - public List Arguments { get; } = new(); - - public AttributeDescription(string? type, string? name) - { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.Name = name ?? throw new ArgumentNullException(nameof(name)); - } + public List Arguments { get; } = []; } diff --git a/src/LivingDocumentation.Descriptions/ConstructorDescription.cs b/src/LivingDocumentation.Descriptions/ConstructorDescription.cs index e87d3c2..aec8f42 100644 --- a/src/LivingDocumentation.Descriptions/ConstructorDescription.cs +++ b/src/LivingDocumentation.Descriptions/ConstructorDescription.cs @@ -1,21 +1,16 @@ namespace LivingDocumentation; [DebuggerDisplay("Constructor {Name}")] -public class ConstructorDescription : MemberDescription, IHaveAMethodBody +public class ConstructorDescription(string name) : MemberDescription(name), IHaveAMethodBody { [JsonProperty(ItemTypeNameHandling = TypeNameHandling.None)] [JsonConverter(typeof(ConcreteTypeConverter>))] - public List Parameters { get; } = new(); + public List Parameters { get; } = []; - public List Statements { get; } = new(); + public List Statements { get; } = []; public override MemberType MemberType => MemberType.Constructor; - public ConstructorDescription(string name) - : base(name) - { - } - [OnDeserialized] internal void OnDeserializedMethod(StreamingContext context) { diff --git a/src/LivingDocumentation.Descriptions/DocumentationComments/DocumentationCommentsDescription.cs b/src/LivingDocumentation.Descriptions/DocumentationComments/DocumentationCommentsDescription.cs index 065ff9f..9f2ee9a 100644 --- a/src/LivingDocumentation.Descriptions/DocumentationComments/DocumentationCommentsDescription.cs +++ b/src/LivingDocumentation.Descriptions/DocumentationComments/DocumentationCommentsDescription.cs @@ -26,15 +26,15 @@ public partial class DocumentationCommentsDescription : IHaveDocumentationCommen [DefaultValue("")] public string Value { get; set; } = string.Empty; - public Dictionary Exceptions { get; set; } = new Dictionary(); + public Dictionary Exceptions { get; set; } = []; - public Dictionary Permissions { get; set; } = new Dictionary(); + public Dictionary Permissions { get; set; } = []; - public Dictionary Params { get; set; } = new Dictionary(); + public Dictionary Params { get; set; } = []; - public Dictionary SeeAlsos { get; set; } = new Dictionary(); + public Dictionary SeeAlsos { get; set; } = []; - public Dictionary TypeParams { get; set; } = new Dictionary(); + public Dictionary TypeParams { get; set; } = []; public static DocumentationCommentsDescription? Parse(string? documentationCommentXml) { diff --git a/src/LivingDocumentation.Descriptions/EnumMemberDescription.cs b/src/LivingDocumentation.Descriptions/EnumMemberDescription.cs index 2ca40d1..e3e8bd2 100644 --- a/src/LivingDocumentation.Descriptions/EnumMemberDescription.cs +++ b/src/LivingDocumentation.Descriptions/EnumMemberDescription.cs @@ -1,15 +1,9 @@ namespace LivingDocumentation; [DebuggerDisplay("EnumMember {Name,nq}")] -public class EnumMemberDescription : MemberDescription +public class EnumMemberDescription(string name, string? value) : MemberDescription(name) { - public string? Value { get; } + public string? Value { get; } = value; public override MemberType MemberType => MemberType.EnumMember; - - public EnumMemberDescription(string name, string? value) - : base(name) - { - this.Value = value; - } } diff --git a/src/LivingDocumentation.Descriptions/EventDescription.cs b/src/LivingDocumentation.Descriptions/EventDescription.cs index d02a286..2ae3259 100644 --- a/src/LivingDocumentation.Descriptions/EventDescription.cs +++ b/src/LivingDocumentation.Descriptions/EventDescription.cs @@ -1,9 +1,9 @@ namespace LivingDocumentation; [DebuggerDisplay("Event {Type,nq} {Name,nq}")] -public class EventDescription : MemberDescription +public class EventDescription(string type, string name) : MemberDescription(name) { - public string Type { get; } + public string Type { get; } = type ?? throw new ArgumentNullException(nameof(type)); public string? Initializer { get; set; } @@ -11,10 +11,4 @@ public class EventDescription : MemberDescription public bool HasInitializer => this.Initializer is not null; public override MemberType MemberType => MemberType.Event; - - public EventDescription(string type, string name) - : base(name) - { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - } } diff --git a/src/LivingDocumentation.Descriptions/FieldDescription.cs b/src/LivingDocumentation.Descriptions/FieldDescription.cs index 134aef0..6bb00bb 100644 --- a/src/LivingDocumentation.Descriptions/FieldDescription.cs +++ b/src/LivingDocumentation.Descriptions/FieldDescription.cs @@ -1,9 +1,9 @@ namespace LivingDocumentation; [DebuggerDisplay("Field {Type,nq} {Name,nq}")] -public class FieldDescription : MemberDescription +public class FieldDescription(string type, string name) : MemberDescription(name) { - public string Type { get; } + public string Type { get; } = type ?? throw new ArgumentNullException(nameof(type)); public string? Initializer { get; set; } @@ -11,10 +11,4 @@ public class FieldDescription : MemberDescription public bool HasInitializer => this.Initializer is not null; public override MemberType MemberType => MemberType.Field; - - public FieldDescription(string type, string name) - : base(name) - { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - } } diff --git a/src/LivingDocumentation.Descriptions/InvocationDescription.cs b/src/LivingDocumentation.Descriptions/InvocationDescription.cs index 24370b6..e2e7841 100644 --- a/src/LivingDocumentation.Descriptions/InvocationDescription.cs +++ b/src/LivingDocumentation.Descriptions/InvocationDescription.cs @@ -1,17 +1,11 @@ namespace LivingDocumentation; [DebuggerDisplay("Invocation \"{ContainingType,nq}.{Name,nq}\"")] -public class InvocationDescription : Statement +public class InvocationDescription(string containingType, string name) : Statement { - public string ContainingType { get; } + public string ContainingType { get; } = containingType ?? throw new ArgumentNullException(nameof(containingType)); - public string Name { get; } + public string Name { get; } = name ?? throw new ArgumentNullException(nameof(name)); - public List Arguments { get; } = new(); - - public InvocationDescription(string containingType, string name) - { - this.ContainingType = containingType ?? throw new ArgumentNullException(nameof(containingType)); - this.Name = name ?? throw new ArgumentNullException(nameof(name)); - } + public List Arguments { get; } = []; } diff --git a/src/LivingDocumentation.Descriptions/Json/ConcreteTypeConverter.cs b/src/LivingDocumentation.Descriptions/Json/ConcreteTypeConverter.cs index f9f2916..e53798c 100644 --- a/src/LivingDocumentation.Descriptions/Json/ConcreteTypeConverter.cs +++ b/src/LivingDocumentation.Descriptions/Json/ConcreteTypeConverter.cs @@ -7,12 +7,12 @@ public override bool CanConvert(Type objectType) return true; } - public override object? ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) { return serializer.Deserialize(reader); } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) { serializer.TypeNameHandling = TypeNameHandling.None; diff --git a/src/LivingDocumentation.Descriptions/LivingDocumentation.Descriptions.csproj b/src/LivingDocumentation.Descriptions/LivingDocumentation.Descriptions.csproj index 3a3bc78..16f1ead 100644 --- a/src/LivingDocumentation.Descriptions/LivingDocumentation.Descriptions.csproj +++ b/src/LivingDocumentation.Descriptions/LivingDocumentation.Descriptions.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 LivingDocumentation @@ -27,7 +27,7 @@ - + diff --git a/src/LivingDocumentation.Descriptions/MemberDescription.cs b/src/LivingDocumentation.Descriptions/MemberDescription.cs index a352987..1ef43b5 100644 --- a/src/LivingDocumentation.Descriptions/MemberDescription.cs +++ b/src/LivingDocumentation.Descriptions/MemberDescription.cs @@ -1,10 +1,10 @@ namespace LivingDocumentation; -public abstract class MemberDescription : IMemberable +public abstract class MemberDescription(string name) : IMemberable { public abstract MemberType MemberType { get; } - public string Name { get; } + public string Name { get; } = name ?? throw new ArgumentNullException("name"); [DefaultValue(Modifier.Private)] [JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] @@ -18,14 +18,9 @@ public abstract class MemberDescription : IMemberable [JsonProperty(ItemTypeNameHandling = TypeNameHandling.None)] [JsonConverter(typeof(ConcreteTypeConverter>))] - public List Attributes { get; } = new(); + public List Attributes { get; } = []; - public MemberDescription(string name) - { - this.Name = name ?? throw new ArgumentNullException("name"); - } - - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is not MemberDescription other) { diff --git a/src/LivingDocumentation.Descriptions/MethodDescription.cs b/src/LivingDocumentation.Descriptions/MethodDescription.cs index 6934b69..5e14d39 100644 --- a/src/LivingDocumentation.Descriptions/MethodDescription.cs +++ b/src/LivingDocumentation.Descriptions/MethodDescription.cs @@ -1,24 +1,18 @@ namespace LivingDocumentation; [DebuggerDisplay("Method {ReturnType,nq} {Name,nq}")] -public class MethodDescription : MemberDescription, IHaveAMethodBody +public class MethodDescription(string? returnType, string name) : MemberDescription(name), IHaveAMethodBody { [DefaultValue("void")] - public string ReturnType { get; } + public string ReturnType { get; } = returnType ?? "void"; [JsonProperty(ItemTypeNameHandling = TypeNameHandling.None)] [JsonConverter(typeof(ConcreteTypeConverter>))] - public List Parameters { get; } = new(); + public List Parameters { get; } = []; - public List Statements { get; } = new(); + public List Statements { get; } = []; public override MemberType MemberType => MemberType.Method; - - public MethodDescription(string? returnType, string name) - : base(name) - { - this.ReturnType = returnType ?? "void"; - } [OnDeserialized] internal void OnDeserializedMethod(StreamingContext context) diff --git a/src/LivingDocumentation.Descriptions/ParameterDescription.cs b/src/LivingDocumentation.Descriptions/ParameterDescription.cs index 40eb39a..c2de16a 100644 --- a/src/LivingDocumentation.Descriptions/ParameterDescription.cs +++ b/src/LivingDocumentation.Descriptions/ParameterDescription.cs @@ -1,21 +1,15 @@ namespace LivingDocumentation; [DebuggerDisplay("Parameter {Type} {Name}")] -public class ParameterDescription : IParameterDescription +public class ParameterDescription(string type, string name) : IParameterDescription { - public string Type { get; } + public string Type { get; } = type ?? throw new ArgumentNullException(nameof(type)); - public string Name { get; } + public string Name { get; } = name ?? throw new ArgumentNullException(nameof(name)); public bool HasDefaultValue { get; set; } [JsonProperty(ItemTypeNameHandling = TypeNameHandling.None)] [JsonConverter(typeof(ConcreteTypeConverter>))] - public List Attributes { get; } = new(); - - public ParameterDescription(string type, string name) - { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - this.Name = name ?? throw new ArgumentNullException(nameof(name)); - } + public List Attributes { get; } = []; } diff --git a/src/LivingDocumentation.Descriptions/PropertyDescription.cs b/src/LivingDocumentation.Descriptions/PropertyDescription.cs index 7533e40..8756c94 100644 --- a/src/LivingDocumentation.Descriptions/PropertyDescription.cs +++ b/src/LivingDocumentation.Descriptions/PropertyDescription.cs @@ -1,9 +1,9 @@ namespace LivingDocumentation; [DebuggerDisplay("Property {Type,nq} {Name,nq}")] -public class PropertyDescription : MemberDescription +public class PropertyDescription(string type, string name) : MemberDescription(name) { - public string Type { get; } + public string Type { get; } = type ?? throw new ArgumentNullException(nameof(type)); public string? Initializer { get; set; } @@ -11,10 +11,4 @@ public class PropertyDescription : MemberDescription public bool HasInitializer => !string.IsNullOrWhiteSpace(this.Initializer); public override MemberType MemberType => MemberType.Property; - - public PropertyDescription(string type, string name) - : base(name) - { - this.Type = type ?? throw new ArgumentNullException(nameof(type)); - } } diff --git a/src/LivingDocumentation.Descriptions/ReturnDescription.cs b/src/LivingDocumentation.Descriptions/ReturnDescription.cs index 2f4d248..ae1ddda 100644 --- a/src/LivingDocumentation.Descriptions/ReturnDescription.cs +++ b/src/LivingDocumentation.Descriptions/ReturnDescription.cs @@ -1,12 +1,7 @@ namespace LivingDocumentation; [DebuggerDisplay("Return {Expression}")] -public class ReturnDescription : Statement +public class ReturnDescription(string expression) : Statement { - public string Expression { get; } - - public ReturnDescription(string expression) - { - this.Expression = expression; - } + public string Expression { get; } = expression; } diff --git a/src/LivingDocumentation.Descriptions/TypeDescription.cs b/src/LivingDocumentation.Descriptions/TypeDescription.cs index 71ce147..0ce3903 100644 --- a/src/LivingDocumentation.Descriptions/TypeDescription.cs +++ b/src/LivingDocumentation.Descriptions/TypeDescription.cs @@ -1,39 +1,33 @@ namespace LivingDocumentation; [DebuggerDisplay("{Type} {Name,nq} ({Namespace,nq})")] -public class TypeDescription : IHaveModifiers +public class TypeDescription(TypeType type, string? fullName) : IHaveModifiers { [JsonProperty(Order = 1, PropertyName = nameof(Fields))] - private readonly List fields = new(); + private readonly List fields = []; [JsonProperty(Order = 2, PropertyName = nameof(Constructors))] - private readonly List constructors = new(); + private readonly List constructors = []; [JsonProperty(Order = 3, PropertyName = nameof(Properties))] - private readonly List properties = new(); + private readonly List properties = []; [JsonProperty(Order = 4, PropertyName = nameof(Methods))] - private readonly List methods = new(); + private readonly List methods = []; [JsonProperty(Order = 5, PropertyName = nameof(EnumMembers))] - private readonly List enumMembers = new(); + private readonly List enumMembers = []; [JsonProperty(Order = 6, PropertyName = nameof(Events))] - private readonly List events = new(); + private readonly List events = []; - public TypeDescription(TypeType type, string? fullName) - { - this.Type = type; - this.FullName = fullName ?? string.Empty; - } - - public TypeType Type { get; } + public TypeType Type { get; } = type; - public string FullName { get; } + public string FullName { get; } = fullName ?? string.Empty; public DocumentationCommentsDescription? DocumentationComments { get; set; } - public List BaseTypes { get; } = new(); + public List BaseTypes { get; } = []; [DefaultValue(Modifier.Internal)] [JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] @@ -41,7 +35,7 @@ public TypeDescription(TypeType type, string? fullName) [JsonProperty(ItemTypeNameHandling = TypeNameHandling.None)] [JsonConverter(typeof(ConcreteTypeConverter>))] - public List Attributes { get; } = new(); + public List Attributes { get; } = []; [JsonIgnore] public string Name => this.FullName.ClassName(); @@ -100,7 +94,7 @@ public void AddMember(MemberDescription member) } } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is not TypeDescription other) { diff --git a/src/LivingDocumentation.Extensions/LivingDocumentation.Extensions.csproj b/src/LivingDocumentation.Extensions/LivingDocumentation.Extensions.csproj index d47505f..a2eb790 100644 --- a/src/LivingDocumentation.Extensions/LivingDocumentation.Extensions.csproj +++ b/src/LivingDocumentation.Extensions/LivingDocumentation.Extensions.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 latest true @@ -25,7 +25,7 @@ - + diff --git a/src/LivingDocumentation.Json/LivingDocumentation.Json.csproj b/src/LivingDocumentation.Json/LivingDocumentation.Json.csproj index 6cc5a9f..558bc05 100644 --- a/src/LivingDocumentation.Json/LivingDocumentation.Json.csproj +++ b/src/LivingDocumentation.Json/LivingDocumentation.Json.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 LivingDocumentation @@ -34,8 +34,8 @@ - - + + diff --git a/src/LivingDocumentation.Render/LivingDocumentation.RenderExtensions.csproj b/src/LivingDocumentation.Render/LivingDocumentation.RenderExtensions.csproj index 7cef455..f4ac828 100644 --- a/src/LivingDocumentation.Render/LivingDocumentation.RenderExtensions.csproj +++ b/src/LivingDocumentation.Render/LivingDocumentation.RenderExtensions.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 LivingDocumentation @@ -27,7 +27,7 @@ - + diff --git a/src/LivingDocumentation.Statements/If.cs b/src/LivingDocumentation.Statements/If.cs index d357f61..f41d8a0 100644 --- a/src/LivingDocumentation.Statements/If.cs +++ b/src/LivingDocumentation.Statements/If.cs @@ -3,7 +3,7 @@ namespace LivingDocumentation; [DebuggerDisplay("If")] public class If : Statement { - public List Sections { get; } = new(); + public List Sections { get; } = []; [JsonIgnore] public override List Statements => this.Sections.SelectMany(s => s.Statements).ToList(); diff --git a/src/LivingDocumentation.Statements/LivingDocumentation.Statements.csproj b/src/LivingDocumentation.Statements/LivingDocumentation.Statements.csproj index dfc31fa..47489e3 100644 --- a/src/LivingDocumentation.Statements/LivingDocumentation.Statements.csproj +++ b/src/LivingDocumentation.Statements/LivingDocumentation.Statements.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 LivingDocumentation @@ -27,7 +27,7 @@ - + diff --git a/src/LivingDocumentation.Statements/Switch.cs b/src/LivingDocumentation.Statements/Switch.cs index 26e5c56..da34b79 100644 --- a/src/LivingDocumentation.Statements/Switch.cs +++ b/src/LivingDocumentation.Statements/Switch.cs @@ -3,7 +3,7 @@ namespace LivingDocumentation; [DebuggerDisplay("Switch {Expression}")] public class Switch : Statement { - public List Sections { get; } = new(); + public List Sections { get; } = []; public string? Expression { get; set; } diff --git a/src/LivingDocumentation.Statements/SwitchSection.cs b/src/LivingDocumentation.Statements/SwitchSection.cs index d64bf70..e0cdd8e 100644 --- a/src/LivingDocumentation.Statements/SwitchSection.cs +++ b/src/LivingDocumentation.Statements/SwitchSection.cs @@ -3,5 +3,5 @@ namespace LivingDocumentation; [DebuggerDisplay("Switch Section {Labels}")] public class SwitchSection : Statement { - public List Labels { get; } = new(); + public List Labels { get; } = []; } diff --git a/src/LivingDocumentation.UML/Fragments/Alt.cs b/src/LivingDocumentation.UML/Fragments/Alt.cs index 4dd13e7..0dff07f 100644 --- a/src/LivingDocumentation.UML/Fragments/Alt.cs +++ b/src/LivingDocumentation.UML/Fragments/Alt.cs @@ -6,7 +6,7 @@ namespace LivingDocumentation.Uml; [DebuggerDisplay("Alt")] public class Alt : InteractionFragment { - private readonly List sections = new(); + private readonly List sections = []; /// /// Gets all sections. diff --git a/src/LivingDocumentation.UML/Fragments/InteractionFragment.cs b/src/LivingDocumentation.UML/Fragments/InteractionFragment.cs index 758c619..46961ab 100644 --- a/src/LivingDocumentation.UML/Fragments/InteractionFragment.cs +++ b/src/LivingDocumentation.UML/Fragments/InteractionFragment.cs @@ -5,7 +5,7 @@ namespace LivingDocumentation.Uml; /// public abstract class InteractionFragment { - private readonly List interactionFragments = new(); + private readonly List interactionFragments = []; /// /// The parent of this fragment. diff --git a/src/LivingDocumentation.UML/LivingDocumentation.UML.csproj b/src/LivingDocumentation.UML/LivingDocumentation.UML.csproj index 2e31fcc..2dc5831 100644 --- a/src/LivingDocumentation.UML/LivingDocumentation.UML.csproj +++ b/src/LivingDocumentation.UML/LivingDocumentation.UML.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 LivingDocumentation.Uml @@ -27,8 +27,8 @@ - - + + diff --git a/tests/LivingDocumentation.Analyzer.Tests/LivingDocumentation.Analyzer.Tests.csproj b/tests/LivingDocumentation.Analyzer.Tests/LivingDocumentation.Analyzer.Tests.csproj index 9842d20..cf3b4a8 100644 --- a/tests/LivingDocumentation.Analyzer.Tests/LivingDocumentation.Analyzer.Tests.csproj +++ b/tests/LivingDocumentation.Analyzer.Tests/LivingDocumentation.Analyzer.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true latest @@ -16,11 +16,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/LivingDocumentation.Descriptions.Tests/LivingDocumentation.Descriptions.Tests.csproj b/tests/LivingDocumentation.Descriptions.Tests/LivingDocumentation.Descriptions.Tests.csproj index bec45b0..2cb1a3a 100644 --- a/tests/LivingDocumentation.Descriptions.Tests/LivingDocumentation.Descriptions.Tests.csproj +++ b/tests/LivingDocumentation.Descriptions.Tests/LivingDocumentation.Descriptions.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true latest @@ -16,11 +16,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/LivingDocumentation.Descriptions.Tests/TypeDescriptionTests.cs b/tests/LivingDocumentation.Descriptions.Tests/TypeDescriptionTests.cs index 64cd431..3d88e31 100644 --- a/tests/LivingDocumentation.Descriptions.Tests/TypeDescriptionTests.cs +++ b/tests/LivingDocumentation.Descriptions.Tests/TypeDescriptionTests.cs @@ -295,12 +295,8 @@ public void TypeDescription_ImplementsTypeStartsWith_DoesNotHaveBaseType_Should_ implementsType.Should().BeFalse(); } - private class UnsupportedMemberDescription : MemberDescription + private class UnsupportedMemberDescription(string name) : MemberDescription(name) { - public UnsupportedMemberDescription(string name) : base(name) - { - } - public override MemberType MemberType => throw new NotImplementedException(); } } diff --git a/tests/LivingDocumentation.Extensions.Tests/LivingDocumentation.Extensions.Tests.csproj b/tests/LivingDocumentation.Extensions.Tests/LivingDocumentation.Extensions.Tests.csproj index 7d5df48..934e4ac 100644 --- a/tests/LivingDocumentation.Extensions.Tests/LivingDocumentation.Extensions.Tests.csproj +++ b/tests/LivingDocumentation.Extensions.Tests/LivingDocumentation.Extensions.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true latest @@ -18,11 +18,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/LivingDocumentation.RenderExtensions.Tests/LivingDocumentation.RenderExtensions.Tests.csproj b/tests/LivingDocumentation.RenderExtensions.Tests/LivingDocumentation.RenderExtensions.Tests.csproj index 6d9e238..e1c624d 100644 --- a/tests/LivingDocumentation.RenderExtensions.Tests/LivingDocumentation.RenderExtensions.Tests.csproj +++ b/tests/LivingDocumentation.RenderExtensions.Tests/LivingDocumentation.RenderExtensions.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true latest @@ -18,11 +18,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/LivingDocumentation.Serializations.Tests/LivingDocumentation.Serializations.Tests.csproj b/tests/LivingDocumentation.Serializations.Tests/LivingDocumentation.Serializations.Tests.csproj index 33291d4..2a49bbb 100644 --- a/tests/LivingDocumentation.Serializations.Tests/LivingDocumentation.Serializations.Tests.csproj +++ b/tests/LivingDocumentation.Serializations.Tests/LivingDocumentation.Serializations.Tests.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 true latest @@ -17,11 +17,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive