Example #1
0
        /// <summary>
        ///     Adds a formula to the formula engine
        /// </summary>
        /// <param name="target">The formula instance to add</param>
        /// <param name="ref">The reference the formula will be bound to</param>
        /// <remarks>
        ///     Use this method when you want to add a formula to the engine.  The engine will bind the formula to the given
        ///     reference
        ///     and analyze its dependencies.  Currently, formulas can only be bound to cell, named, and external references.
        /// </remarks>
        /// <exception cref="System.ArgumentException">
        ///     <list type="bullet">
        ///         <item>The given formula was not created by this engine</item>
        ///         <item>The formula cannot be bound to the type of reference given</item>
        ///         <item>There is already a formula bound to the given reference</item>
        ///     </list>
        /// </exception>
        /// <exception cref="System.ArgumentNullException">target or ref is null</exception>
        public void AddFormula(Formula target, IReference @ref)
        {
            ValidateNonNull(@ref, "ref");
            Reference selfRef = ReferencePool.GetReference((Reference)@ref);

            ValidateAddFormula(target, selfRef);

            SetFormulaDependencyReferences(target);
            target.SetSelfReference(selfRef);

            DependencyManager.AddFormula(target);
            _referenceFormulaMap.Add(selfRef, target);

            CheckFormulaCircularReference(target);
            NotifySelfReference(target);
        }