private bool Equals(ArrayKey <T> other) { if (other == null) { return(false); } if (other._hashCode != _hashCode) { return(false); } if (other._keys.Length != _keys.Length) { return(false); } for (int i = 0; i < _keys.Length; i++) { if (!object.Equals(_keys[i], other._keys[i])) { return(false); } } return(true); }
public override bool Equals(object obj) { ArrayKey key = obj as ArrayKey; if (key != null) { if (key.ItemType == this.ItemType) { return(key.EquipLocation == this.EquipLocation); } } return(false); }
public static Result Run(ArrayCreateExpression expression, Scope scope) { IArray arr = new ArrayStructure(); scope.Root.Arrays.Add(arr); foreach (ArrayItemExpression item_expr in expression.Items) { FinalExpression key_expr = Interpreters.Execute(item_expr.Key, scope).ResultValue; FinalExpression value_expr = Interpreters.Execute(item_expr.Value, scope).ResultValue; ArrayKey key = new ArrayKey(key_expr.GetStringValue()); arr.Set(new ArrayItem(key, value_expr)); } return(new Result(arr.AsExpression)); }
public void CacheByArrayKeyTest() { var cache = new InstanceByKeyCache <string, ArrayKey <int> >(); var key1 = new ArrayKey <int>(new[] { 1, 2, 3 }); var key2 = new ArrayKey <int>(new[] { 1, 2, 3 }); var value = cache.Get(key1, (localKey) => { return("First"); }, CacheDuration); value = cache.Get(key2, (localKey) => { return("Second"); }, CacheDuration); Assert.AreEqual("First", value); }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 2) { throw new WrongParameterCountException(this, expected: 2, actual: parameters.Length); } FinalExpression param_key = parameters [0].EvaluatedValue; FinalExpression param_array = parameters [0].EvaluatedValue; if (param_array is ArrayPointerExpression array_pointer) { ArrayKey key = param_key.GetStringValue(); Log.Debug($"check if array key exists: {key}"); return(new Result(new BoolExpression(array_pointer.Array.Contains(key)))); } else { return(new Result(new BoolExpression(false))); } }
public static void Resolve(ArrayAccessExpression expression, Scope scope, Action <IArray, ArrayKey> action) { FinalExpression key_expr = Interpreters.Execute(expression.Index, scope).ResultValue; ArrayKey key = new ArrayKey(key_expr.GetStringValue()); FinalExpression array_expr = Interpreters.Execute(expression.Array, scope).ResultValue; if (array_expr is ArrayPointerExpression pointer) { if (pointer.Array is IArray arr) { action(arr, key); } else { Log.Error($"Array could not be found: {pointer.Array.Name}, key: '{key}', scope: {scope}"); } } else { Log.Error($"Array access of key '{key}' is not performed on an array, but on: {array_expr}, scope: {scope}"); } }
protected override Result _execute(ImmutableArray <EvaluatedParameter> parameters, FunctionScope function_scope) { if (parameters.Length != 2) { throw new WrongParameterCountException(this, expected: 2, actual: parameters.Length); } FinalExpression param_needle = parameters [0].EvaluatedValue; FinalExpression param_haystack = parameters [0].EvaluatedValue; if (param_haystack is ArrayPointerExpression array_pointer) { ArrayKey needle = param_needle.GetStringValue(); Log.Debug($"check if element is in array: {needle}"); return(new Result(new BoolExpression(array_pointer.Array.GetAll().Any(item => { return Interpreters.Execute(new BinaryExpression(param_needle, item.Value, BinaryOp.EQUAL), function_scope).ResultValue.GetBoolValue(); })))); } else { return(new Result(new BoolExpression(false))); } }