/// <summary> /// Turn expression symbols into lookups of elements on the current item. Attribute must use a function (GetAttribute) due to the need to specify a name. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ProcessSymbol(object sender, SymbolEventArgs e) { if (currentItem == null) { // cant process any symbols if there's nothing to process them on! e.Status = SymbolStatus.UndefinedSymbol; return; } if (Enum.GetNames(typeof(ItemsChoiceType)).Contains(e.Name) && currentItem.ItemsElementName.Contains((ItemsChoiceType)Enum.Parse(typeof(ItemsChoiceType), e.Name))) { e.Result = Convert.ToDouble(currentItem.GetSingleItemByEnum((ItemsChoiceType)Enum.Parse(typeof(ItemsChoiceType), e.Name))); } else if (currentItem.ItemsElementName.Contains(ItemsChoiceType.Attribute) && e.Name.StartsWith("Attribute_", StringComparison.CurrentCulture)) { var attribute = e.Name.Substring(10); e.Result = currentItem.GetAttribute(attribute) == null ? 0 : evaluator.Execute(currentItem.GetAttribute(attribute).value); } // Unknown symbol name else { e.Status = SymbolStatus.UndefinedSymbol; } }
/// <summary> /// This method evaluates a symbol name and returns its value. /// </summary> /// <param name="name">Name of symbol</param> /// <param name="pos">Position at start of symbol</param> /// <returns></returns> protected double EvaluateSymbol(string name, int pos) { double result = default(double); // We found a symbol reference SymbolStatus status = SymbolStatus.UndefinedSymbol; if (ProcessSymbol != null) { SymbolEventArgs args = new SymbolEventArgs(); args.Name = name; args.Result = result; args.Status = SymbolStatus.OK; ProcessSymbol(this, args); result = args.Result; status = args.Status; } if (status == SymbolStatus.UndefinedSymbol) { throw new EvalException(String.Format(ErrUndefinedSymbol, name), pos); } return(result); }
/// <summary> /// This method evaluates a symbol name and returns its value. /// </summary> /// <param name="name">Name of symbol</param> /// <param name="pos">Position at start of symbol</param> /// <returns></returns> protected double EvaluateSymbol(string name, int pos) { double result = default(double); // We found a symbol reference SymbolStatus status = SymbolStatus.UndefinedSymbol; if(ProcessSymbol != null) { SymbolEventArgs args = new SymbolEventArgs(); args.Name = name; args.Result = result; args.Status = SymbolStatus.OK; ProcessSymbol(this, args); result = args.Result; status = args.Status; } if(status == SymbolStatus.UndefinedSymbol) throw new EvalException(String.Format(ErrUndefinedSymbol, name), pos); return result; }