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

namespace FormulaEditor
{
    public class DrawableConverter : IMathSymbolConverter
    {

        public static readonly DrawableConverter Object = new DrawableConverter();

        public static readonly string Drawable = "Drawable";



        private DrawableConverter()
        {
        }

        #region IMathSymbolConverter Members

        public MathSymbol Convert(MathSymbol symbol)
        {
            Type t = symbol.GetType();
            string type = t.ToString();
            if (type.Length > Drawable.Length)
            {
                if (type.Substring(type.Length - Drawable.Length).Equals(Drawable))
                {
                    type = type.Substring(0, type.Length - Drawable.Length);
                }
            }
            string typeDrawable = type + Drawable;
            Type tDrawable = Type.GetType(typeDrawable);
            System.Reflection.ConstructorInfo c = tDrawable.GetConstructor(new Type[] { t });
            MathSymbol sym = c.Invoke(new object[] { symbol }) as MathSymbol;
            return sym;
        }

        #endregion
    }
}
