using System;
using System.Collections.Generic;
using System.Text;

namespace FormulaEditor
{
    /// <summary>
    /// Binary operation acceptor with array
    /// </summary>
    public class BinaryArrayOperationAcceptor : IBinaryAcceptor
    {
        #region Fields

        /// <summary>
        /// Operation acceptor
        /// </summary>
        private IBinaryAcceptor acceptor;


        #endregion

        #region Constructors
        public BinaryArrayOperationAcceptor(IBinaryAcceptor acceptor)
        {
            this.acceptor = acceptor;
        }
        #endregion

        #region IBinaryAcceptor Members

        public IObjectOperation Accept(object typeA, object typeB)
        {
            if (!(typeA is ArrayReturnType) & !(typeB is ArrayReturnType))
            {
                return acceptor.Accept(typeA, typeB);
            }
            object[] types = new object[] { typeA, typeB };
            for (int i = 0; i < 2; i++)
            {
                types[i] = ArrayReturnType.GetBaseType(types[i]);
            }
            IObjectOperation op = acceptor.Accept(types[0], types[1]);
            if (op != null)
            {
                return new BinaryArrayOperation(op, typeA, typeB);
            }
            return null;
        }

        #endregion
    }

}
