Includes actions for base types.

This commit is contained in:
2023-11-29 21:55:06 +08:00
parent ed6ae7ad8a
commit 820aaeff85
2 changed files with 10 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Cryville.Crtr.Browsing.Actions {
public class ActionManager {
@@ -40,8 +41,14 @@ namespace Cryville.Crtr.Browsing.Actions {
Unregister(typeof(T), action);
}
public IReadOnlyCollection<IResourceAction> GetActions(Type type) {
return _actions[type];
public IEnumerable<IResourceAction> GetActions(Type type) {
List<IResourceAction> actions;
if (!_actions.TryGetValue(type, out actions)) {
actions = new List<IResourceAction>();
}
IEnumerable<IResourceAction> result = actions;
if (type != typeof(object)) result = result.Concat(GetActions(type.BaseType));
return result;
}
}
}