Skip to content

Commit

Permalink
Scanner selector based on assembly type
Browse files Browse the repository at this point in the history
  • Loading branch information
gubpalma committed Jan 19, 2024
1 parent b821ba9 commit 5c90c65
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/6.0/Siren.Infrastructure.AssemblyLoad/AssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Linq;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Siren.Infrastructure.AssemblyLoad
{
public static class AssemblyLoader
{
public static bool IsASnapshotAssembly(this Assembly assembly)
{
return
assembly
.GetTypes()
.Any(
o => o.BaseType == typeof(ModelSnapshot)
);
}
}
}
29 changes: 25 additions & 4 deletions src/6.0/Siren.Tool/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Reflection;
using Siren.Domain;
using Siren.Infrastructure.AssemblyLoad;
using Siren.Infrastructure.Io;
using Siren.Infrastructure.Mermaid;
Expand All @@ -27,22 +28,42 @@
throw new Exception("Output path argument invalid");

Assembly assembly;
var isASnapshotAssembly = false;

try
{
assembly =
Assembly
.LoadFrom(assemblyPath);

isASnapshotAssembly =
assembly
.IsASnapshotAssembly();
}
catch (FileNotFoundException)
{
throw new Exception($"Could not load assembly from {assemblyPath}");
}

var universe =
// AssemblyScanner
SnapshotAssemblyScanner
.Perform(assembly);
Universe universe;

if (isASnapshotAssembly) {
Console
.WriteLine("ModelSnapshot type found in assembly... scanning...");

universe =
SnapshotAssemblyScanner
.Perform(assembly);
}
else
{
Console
.WriteLine("POCO default assembly... scanning...");

universe =
PocoAssemblyScanner
.Perform(assembly);
}

var result =
MermaidRenderer
Expand Down

0 comments on commit 5c90c65

Please sign in to comment.