1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- 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<VariableAttribute, Func<EraRuntime, int[], Value>> StaticVariables { get; } = _getFunctions();
- private static Dictionary<VariableAttribute, Func<EraRuntime, int[], Value>> _getFunctions()
- {
- var output = new Dictionary<VariableAttribute, Func<EraRuntime, int[], Value>>();
- foreach (MethodInfo method in typeof(Variables).GetMethods(BindingFlags.Public | BindingFlags.Static))
- {
- var variable = method.GetCustomAttribute<VariableAttribute>();
- if (variable != null)
- output[variable] = (Func<EraRuntime, int[], Value>)Delegate.CreateDelegate(typeof(Func<EraRuntime, int[], Value>), method);
- }
- return output;
- }
- [Variable("LINECOUNT", ValueType.Real)]
- public static Value LineCount(EraRuntime runtime, int[] index)
- {
- return runtime.Console.LineCount;
- }
- }
- }
|