using System; using System.Collections.Generic; using System.Reflection; namespace NTERA.Engine.Runtime.Base { public static class Variables { public class VariableAttribute : Attribute { public string Name { get; } public ValueType Type { get; } public VariableAttribute(string name, ValueType type) { Name = name; Type = type; } } public static Dictionary> StaticVariables { get; } = _getFunctions(); private static Dictionary> _getFunctions() { var output = new Dictionary>(); foreach (MethodInfo method in typeof(Variables).GetMethods(BindingFlags.Public | BindingFlags.Static)) { var variable = method.GetCustomAttribute(); if (variable != null) output[variable] = (Func)Delegate.CreateDelegate(typeof(Func), method); } return output; } [Variable("LINECOUNT", ValueType.Real)] public static Value LineCount(EraRuntime runtime, int[] index) { return runtime.Console.LineCount; } } }