Draft config definition.

This commit is contained in:
2023-07-27 15:59:56 +08:00
parent ba2f1d4858
commit 86da71f2cb
3 changed files with 31 additions and 1 deletions

View File

@@ -100,6 +100,26 @@ namespace Cryville.Crtr {
_cb(GetOperand(0).AsIdentifier());
}
}
public class Enum : PropOp {
readonly Type _type;
readonly IntKeyedDictionary<int> _cache = new IntKeyedDictionary<int>();
readonly Action<object> _cb;
public Enum(Type type, Action<object> cb) {
if (!type.IsEnum)
throw new ArgumentException("Type is not enum");
_type = type;
var names = type.GetFields(BindingFlags.Public | BindingFlags.Static);
for (int i = 0; i < names.Length; i++)
_cache[IdentifierManager.Shared.Request(names[i].Name)] = Convert.ToInt32(names[i].GetValue(null));
_cb = cb;
}
protected override void Execute() {
int result = 0;
for (int i = 0; i < LoadedOperandCount; i++)
result |= _cache[GetOperand(i).AsIdentifier()];
_cb(System.Enum.ToObject(_type, result));
}
}
public class Enum<T> : PropOp {
static readonly IntKeyedDictionary<int> _cache = new IntKeyedDictionary<int>();
readonly Action<T> _cb;