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

namespace DataPerformer
{
    public class MeasureDerivation : Measure, IDerivation
    {
        protected MeasureParameter derivation;

        public MeasureDerivation(object type, MeasureParameter parameter, MeasureParameter derivation, string name)
            : base(type, parameter, name)
        {
            if (derivation == null)
            {
                derivation = derivation;
            }
            this.derivation = derivation;
        }

        #region IDerivation Members

        double IDerivation.Derivation
        {
            get { return (double)derivation(); }
        }

        #endregion

        public static MeasureParameter GetDerivation(IMeasure m)
        {
            if (m is IDerivation)
            {
                DerivationHelp dh = new DerivationHelp(m as IDerivation);
                return dh.Parameter;
            }
            return null;
        }

        class DerivationHelp
        {
            IDerivation d;
            MeasureParameter p;
            internal DerivationHelp(IDerivation d)
            {
                this.d = d;
                p = get;
            }
            object get()
            {
                return d.Derivation;
            }

            internal MeasureParameter Parameter
            {
                get
                {
                    return p;
                }
            }

        }

    }
}
