From 5a117247dd3a18ca465eae3bda87ab23fc9aa018 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R." Date: Sun, 3 Dec 2023 18:09:06 +0100 Subject: [PATCH] AdventOfCode.Common.DayHelper: Fix type search --- AdventOfCode.Common/DayHelper.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/AdventOfCode.Common/DayHelper.cs b/AdventOfCode.Common/DayHelper.cs index d694251..3688ce7 100644 --- a/AdventOfCode.Common/DayHelper.cs +++ b/AdventOfCode.Common/DayHelper.cs @@ -1,7 +1,20 @@ +using System.Reflection; + namespace AdventOfCode.Common; public static class DayHelper { + private static Type? GetTypeByString(string strType) + { + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + foreach (Assembly assembly in assemblies) + { + Type? type = assembly.GetTypes().FirstOrDefault(t => t.FullName == strType); + if (type != null) { return type; } + } + return null; + } + public static void RunDay(string eventName, int dayNumber) { Console.WriteLine($"Day {dayNumber:00}"); @@ -9,7 +22,7 @@ public static class DayHelper Console.WriteLine(); IDay? currentDay = null; - Type? dayType = Type.GetType($"{eventName}.Day{dayNumber:00}"); + Type? dayType = GetTypeByString($"{eventName}.Day{dayNumber:00}"); if (dayType != null) { currentDay = Activator.CreateInstance(dayType) as IDay;