AdventOfCode.Common.DayHelper: Fix type search
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user