Skip to content

Commit

Permalink
Merge pull request #65 from eNeRGy164/upgrade-dotnet8
Browse files Browse the repository at this point in the history
Upgrade to dotnet 8
  • Loading branch information
eNeRGy164 authored Dec 22, 2023
2 parents cb30357 + 5114549 commit ac06ef4
Show file tree
Hide file tree
Showing 48 changed files with 210 additions and 337 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[*]
indent_style = space

[*.{csproj,xml}]
[*.{csproj,xml,runsettings}]
indent_size = 2

# Code files
Expand Down
14 changes: 14 additions & 0 deletions LivingDocumentation.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
<Format>lcov,cobertura</Format>
</Configuration>
</DataCollector>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Include>
<ModulePath>.*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*\.Tests\.dll$</ModulePath>
</Exclude>
</ModulePaths>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
33 changes: 11 additions & 22 deletions samples/LivingDocumentation.eShopOnContainers/AsciiDocRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -8,21 +8,10 @@

namespace LivingDocumentation.eShopOnContainers
{
public class AsciiDocRenderer
public partial class AsciiDocRenderer(IReadOnlyList<TypeDescription> types, IReadOnlyDictionary<string, string> aggregateFiles, IReadOnlyDictionary<string, string> commandHandlerFiles, IReadOnlyDictionary<string, string> eventHandlerFiles)
{
private readonly IReadOnlyList<TypeDescription> types;
private readonly IReadOnlyDictionary<string, string> aggregateFiles;
private readonly IReadOnlyDictionary<string, string> commandHandlerFiles;
private readonly IReadOnlyDictionary<string, string> eventHandlerFiles;
private static readonly Regex replaceTypeSuffix = new Regex("(?:(?:Command|(?:Domain|Integration)Event))(?:Handler)?$", RegexOptions.CultureInvariant);

public AsciiDocRenderer(IReadOnlyList<TypeDescription> types, IReadOnlyDictionary<string, string> aggregateFiles, IReadOnlyDictionary<string, string> commandHandlerFiles, IReadOnlyDictionary<string, string> 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()
{
Expand All @@ -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()}[]");
Expand All @@ -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)}");
Expand Down Expand Up @@ -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()}[]");
Expand Down Expand Up @@ -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)}");
Expand Down Expand Up @@ -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()}[]");
Expand Down Expand Up @@ -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)}");
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using PlantUml.Builder;
using PlantUml.Builder;
using System;
using System.Linq;

Expand Down Expand Up @@ -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//<<DomainEventHandler>>//";
return name[..^DomainEventHandler.Length] + "\\n//<<DomainEventHandler>>//";
}

if (name.EndsWith(CommandHandler))
{
return name.Substring(0, name.Length - CommandHandler.Length) + "\\n//<<CommandHandler>>//";
return name[..^CommandHandler.Length] + "\\n//<<CommandHandler>>//";
}

return name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>

<RootNamespace>LivingDocumentation</RootNamespace>

Expand All @@ -27,8 +27,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/LivingDocumentation.Abstractions/Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace LivingDocumentation;
public abstract class Statement
{
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.Objects)]
public virtual List<Statement> Statements { get; } = new();
public virtual List<Statement> Statements { get; } = [];

[JsonIgnore]
public object? Parent
Expand Down
21 changes: 6 additions & 15 deletions src/LivingDocumentation.Analyzer/Analyzers/BranchingAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
namespace LivingDocumentation;

internal class BranchingAnalyzer : CSharpSyntaxWalker
internal class BranchingAnalyzer(SemanticModel semanticModel, List<Statement> statements) : CSharpSyntaxWalker
{
private readonly SemanticModel semanticModel;
private readonly List<Statement> statements;

public BranchingAnalyzer(in SemanticModel semanticModel, List<Statement> 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;
Expand All @@ -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))
Expand All @@ -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();

Expand All @@ -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);
}
}
Expand Down
Loading

0 comments on commit ac06ef4

Please sign in to comment.