コード例 #1
0
        /// <summary>
        /// Resolves a provided reference of forms "X" or "X.Y" and passes back the first given or
        /// derivation which matches.
        /// </summary>
        /// <param name="reference">The string reference for the given or derivative</param>
        /// <returns>An IValue representing either the given or derivation the reference points to.</returns>
        internal IValue ResolveReference(string reference, string ElementScope)
        {
            //Find near givens with a full reference first.
            IValue val = Givens.Find(t => t.Key == ElementScope + "." + reference);

            if (val == null)
            {
                //Ok, try near givens with a partial reference
                val = Givens.Find(t => t.Key == reference);
            }
            //Ok, givens exhausted; find me a derivation with that reference.
            if (val == null)
            {
                string[] references = reference.Split('.');
                Element  el         = Elements.Find(t => t.ElementName == references[0]);
                if (el == null)
                {
                    throw new ArgumentException("Unable to reference expression element");
                }
                val = el.Derivations.Find(t => t.Name == references[1]);
            }
            return(val);
        }