public void SetValue(string identifier, object value) { string[] suffixes = identifier.Split(':'); Variable variable = GetOrCreateVariable(suffixes[0]); if (suffixes.Length > 1 && variable.Value is SpecialValue) { SpecialValue specialValue = (SpecialValue)variable.Value; string suffixName; if (suffixes.Length > 2) { for (int suffixIndex = 1; suffixIndex < (suffixes.Length - 1); suffixIndex++) { suffixName = suffixes[suffixIndex].ToUpper(); specialValue = (SpecialValue)specialValue.GetSuffix(suffixName); if (specialValue == null) { throw new Exception(string.Format("Suffix {0} not found on object {1}", suffixName, variable.Name)); } } } suffixName = suffixes[suffixes.Length - 1].ToUpper(); if (!specialValue.SetSuffix(suffixName, value)) { throw new Exception(string.Format("Suffix {0} not found on object {1}", suffixName, variable.Name)); } } else { variable.Value = value; } }
private bool TryParseSuffix(string text) { Match match = Regex.Match(text, "^([A-Z0-9_\\-]+?):([A-Z0-9_\\-]+?)$", RegexOptions.IgnoreCase); if (match.Success) { var obj = new Expression(match.Groups[1].Value, executionContext).GetValue(); if (obj is SpecialValue) { SpecialValue = (SpecialValue)obj; Suffix = match.Groups[2].Value.ToUpper(); Value = SpecialValue.GetSuffix(Suffix); return(true); } } return(false); }
private bool TryParseSuffix(string text) { Match match = Regex.Match(text, "^([A-Z0-9_\\-]+?):([A-Z0-9_\\-]+?)$", RegexOptions.IgnoreCase); if (match.Success) { var obj = new Expression(match.Groups[1].Value, executionContext).GetValue(); if (obj is SpecialValue) { SpecialValue = (SpecialValue)obj; Suffix = match.Groups[2].Value.ToUpper(); Value = SpecialValue.GetSuffix(Suffix); return true; } } return false; }
// Evaluate and return the value of the part of an expression that this instance represents public object GetValue() { if (EvalDlg != null) { EvalDlg(); } if (SpecialValue != null) { if (string.IsNullOrEmpty(Suffix)) { return(SpecialValue.ToString()); } else { return(SpecialValue.GetSuffix(Suffix)); } } if (LeftSide == null) { if (Variable != null && !IsStatic) { return(Variable.Value); } else { return(Value); } } else { if (Operator == "AND") { return(LeftSide.Bool() && RightSide.Bool()); } if (Operator == "OR") { return(LeftSide.Bool() || RightSide.Bool()); } if (LeftSide.Value is String || RightSide.Value is String) { if (Operator == "+") { return(LeftSide.Value.ToString() + RightSide.Value.ToString()); } if (Operator == "==") { return(LeftSide.Value.ToString() == RightSide.Value.ToString()); } if (Operator == "=") { return(LeftSide.Value.ToString() == RightSide.Value.ToString()); } if (Operator == "!=") { return(LeftSide.Value.ToString() != RightSide.Value.ToString()); } } if (LeftSide.Value is float || RightSide.Value is float) { if (Operator == "+") { return(LeftSide.Float() + RightSide.Float()); } if (Operator == "-") { return(LeftSide.Float() - RightSide.Float()); } if (Operator == "/") { return(LeftSide.Float() / RightSide.Float()); } if (Operator == "*") { return(LeftSide.Float() * RightSide.Float()); } if (Operator == "^") { return((float)Math.Pow(LeftSide.Double(), RightSide.Double())); } if (Operator == "<") { return(LeftSide.Float() < RightSide.Float()); } if (Operator == ">") { return(LeftSide.Float() > RightSide.Float()); } if (Operator == "<=") { return(LeftSide.Float() <= RightSide.Float()); } if (Operator == ">=") { return(LeftSide.Float() >= RightSide.Float()); } if (Operator == "==") { return(LeftSide.Float() == RightSide.Float()); } if (Operator == "=") { return(LeftSide.Float() == RightSide.Float()); } if (Operator == "!=") { return(LeftSide.Float() != RightSide.Float()); } } if (LeftSide.Value is Direction && RightSide.Value is Direction) { if (Operator == "*") { return((Direction)LeftSide.GetValue() * (Direction)RightSide.GetValue()); } if (Operator == "+") { return((Direction)LeftSide.GetValue() + (Direction)RightSide.GetValue()); } if (Operator == "-") { return((Direction)LeftSide.GetValue() + (Direction)RightSide.GetValue()); } } } throw new kOSException("Expression error."); }