31 lines
923 B
C#
31 lines
923 B
C#
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<string, BangOperation> Registry = new();
|
|
|
|
public abstract string Name { get; }
|
|
|
|
protected BangOperation()
|
|
{
|
|
Registry[Name] = this;
|
|
}
|
|
|
|
public abstract Context Execute(Context ctx, IEnumerable<string> 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);
|
|
}
|
|
}
|
|
} |