using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using XNeedle.Parser.Elements; namespace XNeedle.Transformation { public abstract class BangOperation { private static readonly Dictionary Registry = new(); public abstract string Name { get; } protected BangOperation() { Registry[Name] = this; } public abstract Context Execute(Context ctx, IEnumerable arguments); public static BangOperation? Resolve(string name) => Registry.TryGetValue(name, out var op) ? op : null; public static void RegisterAll() { foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) if (!type.IsAbstract && type.IsSubclassOf(typeof(BangOperation))) Activator.CreateInstance(type); } } }