예제 #1
0
        /// <summary>
        /// Registers a global binary operator.
        /// </summary>
        /// <param name="symbol">The symbol of the operator, e.g., +.</param>
        /// <param name="a">The type on the left side of the expression.</param>
        /// <param name="b">The type on the right side of the expression.</param>
        /// <param name="handler">The handler to invoke.</param>
        public static void BinaryOperator(String symbol, Type a, Type b, Func<Value, Value, Value> handler)
        {
            var mapping = default(BinaryOperatorMappingList);

            if (BinaryMappings.TryGetValue(symbol, out mapping))
            {
                var item = new BinaryOperatorMapping(a, b, handler);
                mapping.With(item);
            }
        }
        /// <summary>
        /// Includes the specified operator in the list.
        /// </summary>
        public void With(BinaryOperatorMapping item)
        {
            var i = 0;
            var count = Count;

            while (i < count && !_mapping[i].Equals(item))
            {
                i++;
            }

            if (i == count)
            {
                _mapping.Add(item);
            }
        }