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

namespace FormulaEditor
{
    public class ArrayReturnType
    {
        object elementType;
        int[] dimension;


        public ArrayReturnType(object elementType, int[] dimension)
        {
            this.elementType = elementType;
            this.dimension = dimension;
        }

        public int[] Dimension
        {
            get
            {
                return dimension;
            }
        }

        public object ElementType
        {
            get
            {
                return elementType;
            }
        }

        public override bool Equals(object obj)
        {
            if (!(obj is ArrayReturnType))
            {
                return false;
            }
            ArrayReturnType at = obj as ArrayReturnType;
            if (!at.elementType.Equals(elementType))
            {
                return false;
            }
            if (at.dimension.Length != dimension.Length)
            {
                return false;
            }
            for (int i = 0; i < dimension.Length; i++)
            {
                if (dimension[i] != at.dimension[i])
                {
                    return false;
                }
            }
            return true;
        }

        public override int GetHashCode()
        {
            return dimension.Length * dimension[0];
        }

        public bool HasEqualDimension(ArrayReturnType type)
        {
            if (type.dimension.Length != dimension.Length)
            {
                return false;
            }
            for (int i = 0; i < dimension.Length; i++)
            {
                if (dimension[i] != type.dimension[i])
                {
                    return false;
                }
            }
            return true;
        }

        static public object GetBaseType(object o)
        {
            if (o is ArrayReturnType)
            {
                ArrayReturnType rt = o as ArrayReturnType;
                return rt.elementType;
            }
            return o;
        }
    }
}
