private ExpressionResultPair GetTail(string tailName) { Utility.AssertNotNull(tailName, "name"); ExpressionResultPair pair = null; _myNameNodeMap.TryGetValue(tailName, out pair); return(pair); }
/// <summary> /// Called by an expression when it references another expression in the engine /// </summary> /// <param name="tailName"></param> /// <param name="context"></param> internal void AddDependency(string tailName, ExpressionContext context) { ExpressionResultPair actualTail = this.GetTail(tailName); string headName = context.CalcEngineExpressionName; ExpressionResultPair actualHead = this.GetTail(headName); // An expression could depend on the same reference more than once (ie: "a + a * a") _myDependencies.AddDepedency(actualTail, actualHead); }
public string[] GetPrecedents(string name) { ExpressionResultPair pair = this.GetTail(name); List <ExpressionResultPair> dependents = new List <ExpressionResultPair>(); if ((pair != null)) { _myDependencies.GetDirectPrecedents(pair, dependents); } return(this.GetNames(dependents)); }
private ExpressionResultPair GetTailWithValidate(string tailName) { Utility.AssertNotNull(tailName, "name"); ExpressionResultPair pair = this.GetTail(tailName); if (pair == null) { throw new ArgumentException($"No expression is associated with the name '{tailName}'"); } else { return(pair); } }
public T GetResult <T>(string name) { ExpressionResultPair tail = this.GetTailWithValidate(name); if ((!object.ReferenceEquals(typeof(T), tail.ResultType))) { string msg = $"The result type of '{name}' ('{tail.ResultType.Name}') does not match the supplied type argument ('{typeof(T).Name}')"; throw new ArgumentException(msg); } GenericExpressionResultPair <T> actualTail = (GenericExpressionResultPair <T>)tail; return(actualTail.Result); }
private ExpressionResultPair[] GetRootTails(string[] roots) { // No roots supplied so get everything if (roots.Length == 0) { return(_myDependencies.GetTails()); } // Get the tail for each name ExpressionResultPair[] arr = new ExpressionResultPair[roots.Length]; for (int i = 0; i <= arr.Length - 1; i++) { arr[i] = this.GetTailWithValidate(roots[i]); } return(arr); }
public bool Remove(string name) { ExpressionResultPair tail = this.GetTail(name); if (tail == null) { return(false); } ExpressionResultPair[] dependents = _myDependencies.GetDependents(tail); _myDependencies.Remove(dependents); foreach (ExpressionResultPair pair in dependents) { _myNameNodeMap.Remove(pair.Name); } return(true); }
internal void FixTemporaryHead(IDynamicExpression expression, ExpressionContext context, Type resultType) { Type pairType = typeof(GenericExpressionResultPair <>); pairType = pairType.MakeGenericType(resultType); ExpressionResultPair pair = (ExpressionResultPair)Activator.CreateInstance(pairType); string headName = context.CalcEngineExpressionName; pair.SetName(headName); pair.SetExpression(expression); ExpressionResultPair oldPair = _myNameNodeMap[headName]; _myDependencies.ReplaceDependency(oldPair, pair); _myNameNodeMap[headName] = pair; // Let the pair store the result of its expression pair.Recalculate(); }
public bool HasPrecedents(string name) { ExpressionResultPair pair = this.GetTail(name); return((pair != null) && _myDependencies.HasPrecedents(pair)); }
public IExpression GetExpression(string name) { ExpressionResultPair tail = this.GetTailWithValidate(name); return(tail.Expression); }
public object GetResult(string name) { ExpressionResultPair tail = this.GetTailWithValidate(name); return(tail.ResultAsObject); }
internal Type ResolveTailType(string tailName) { ExpressionResultPair actualTail = this.GetTail(tailName); return(actualTail.ResultType); }