/// <summary> /// Adds a binary operator. /// </summary> /// <param name="operator">The operator's operation code.</param> /// <param name="supportedTypes">The supported types on both sides of the operator.</param> /// <param name="func">The logic to perform this operator.</param> /// <param name="order">The order the left/right values may appear in.</param> /// <exception cref="System.ArgumentNullException">Thrown if <see cref="supportedTypes" /> or <see cref="func" /> is null.</exception> public void AddBinaryOperator(OpCode @operator, Type[] supportedTypes, Func<EarleValue, EarleValue, EarleValue> func, EarleOperatorParamOrder order = EarleOperatorParamOrder.Normal) { if (supportedTypes == null) throw new ArgumentNullException(nameof(supportedTypes)); if (func == null) throw new ArgumentNullException(nameof(func)); AddBinaryOperator(@operator, supportedTypes, supportedTypes, func, order); }
/// <summary> /// Adds a binary operator. /// </summary> /// <param name="operator">The operator's operation code.</param> /// <param name="supportedLeftTypes">The supported types on the left side of the operator.</param> /// <param name="supportedRightTypes">The supported types on the right side of the operator.</param> /// <param name="func">The logic to perform this operator.</param> /// <param name="order">The order the left/right values may appear in.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown if <see cref="supportedLeftTypes" />, /// <see cref="supportedRightTypes" /> or <see cref="func" /> is null. /// </exception> public void AddBinaryOperator(OpCode @operator, Type[] supportedLeftTypes, Type[] supportedRightTypes, Func<EarleValue, EarleValue, EarleValue> func, EarleOperatorParamOrder order = EarleOperatorParamOrder.Normal) { if (supportedLeftTypes == null) throw new ArgumentNullException(nameof(supportedLeftTypes)); if (supportedRightTypes == null) throw new ArgumentNullException(nameof(supportedRightTypes)); if (func == null) throw new ArgumentNullException(nameof(func)); foreach (var left in supportedLeftTypes) foreach (var right in supportedRightTypes) AddBinaryOperator(@operator, left, right, func, order); }
/// <summary> /// Adds a binary operator. /// </summary> /// <param name="operator">The operator's operation code.</param> /// <param name="supportedLeftType">The supported type on the left side of the operator.</param> /// <param name="supportedRightType">The supported type on the right side of the operator.</param> /// <param name="func">The logic to perform this operator.</param> /// <param name="order">The order the left/right values may appear in.</param> /// <exception cref="System.ArgumentNullException">Thrown if <see cref="func" /> is null.</exception> public void AddBinaryOperator(OpCode @operator, Type supportedLeftType, Type supportedRightType, Func<EarleValue, EarleValue, EarleValue> func, EarleOperatorParamOrder order = EarleOperatorParamOrder.Normal) { if (func == null) throw new ArgumentNullException(nameof(func)); _binaryOperators[new Tuple<OpCode, Type, Type>(@operator, supportedLeftType, supportedRightType)] = new Tuple<bool, Func<EarleValue, EarleValue, EarleValue>>(order == EarleOperatorParamOrder.Swap, func); if (order == EarleOperatorParamOrder.Any) AddBinaryOperator(@operator, supportedRightType, supportedLeftType, func); if (order == EarleOperatorParamOrder.Specified) AddBinaryOperator(@operator, supportedRightType, supportedLeftType, func, EarleOperatorParamOrder.Swap); }