diff --git a/Ktisis/Ktisis.cs b/Ktisis/Ktisis.cs index cbe66b742..f90cedf7e 100644 --- a/Ktisis/Ktisis.cs +++ b/Ktisis/Ktisis.cs @@ -121,12 +121,7 @@ private void OnCommand(string command, string arguments) { private static readonly Stack ToGloballyDispose = new(); private static void GlobalInit() { - foreach (Type globalStateContainer in - typeof(Ktisis).Assembly.GetTypes() - .Where(type => type.CustomAttributes - .Any(attr => attr.AttributeType == typeof(GlobalStateAttribute)) - ) - ) { + foreach (Type globalStateContainer in GetGlobalInitTypes()) { foreach (var method in globalStateContainer.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)) { foreach (var attr in method.CustomAttributes) { if (attr.AttributeType == typeof(GlobalInitAttribute)) @@ -139,6 +134,10 @@ private static void GlobalInit() { ToGloballyDispose.TrimExcess(); } + private static IEnumerable GetGlobalInitTypes() => + typeof(Ktisis).Assembly.GetTypes() + .Where(x => x.CustomAttributes.Any(x => x.AttributeType == typeof(GlobalStateAttribute))); + private static void GlobalDispose() { while (ToGloballyDispose.TryPop(out MethodInfo? toDispose)) { toDispose.Invoke(null, Array.Empty());