Skip to content

Commit

Permalink
Load assemblies using explicit dependency list
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Oct 16, 2020
1 parent 3d8ce73 commit ffb9357
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion Libplanet.Analyzers.Tests/Verifiers/DiagnosticVerifier.Helper.cs
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using Bencodex.Types;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Emit;
Expand Down Expand Up @@ -175,7 +176,14 @@ private static Document[] GetDocuments(string[] sources, string language)
var solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language);
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
IEnumerable<Assembly> assemblies = GetAssemblies(
typeof(object),
typeof(Enumerable),
typeof(Compilation),
typeof(Address),
typeof(IValue)
);
foreach (Assembly assembly in assemblies)
{
if (assembly.IsDynamic)
{
Expand All @@ -199,5 +207,34 @@ private static Document[] GetDocuments(string[] sources, string language)

return solution.GetProject(projectId);
}

private static IEnumerable<Assembly> GetAssemblies(params Type[] rootTypes)
{
var registry = new Dictionary<string, Assembly>();

void Register(Assembly assembly)
{
if (assembly.IsDynamic || registry.ContainsKey(assembly.FullName))
{
return;
}

registry.Add(assembly.FullName, assembly);
foreach (AssemblyName @ref in assembly.GetReferencedAssemblies())
{
if (!registry.ContainsKey(@ref.FullName))
{
Register(Assembly.Load(@ref));
}
}
}

foreach (Type rootType in rootTypes)
{
Register(rootType.Assembly);
}

return registry.Values;
}
}
}

0 comments on commit ffb9357

Please sign in to comment.