Draft config definition.
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user