Skip to content

Commit

Permalink
Extract GlobalState type searching to own method
Browse files Browse the repository at this point in the history
  • Loading branch information
Fayti1703 committed Jan 1, 2023
1 parent cec3c71 commit 968a90e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Ktisis/Ktisis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,7 @@ private void OnCommand(string command, string arguments) {
private static readonly Stack<MethodInfo> 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))
Expand All @@ -139,6 +134,10 @@ private static void GlobalInit() {
ToGloballyDispose.TrimExcess();
}

private static IEnumerable<Type> 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<object>());
Expand Down

0 comments on commit 968a90e

Please sign in to comment.