private XElement ExecuteInnerFunctions(FunctionContextContainer contextContainer) { XElement resultRoot = new XElement(_element); int loopCount = 0; while (true) { XName functionXName = Namespaces.Function10 + FunctionTreeConfigurationNames.FunctionTagName; IEnumerable <XElement> nestedFunctionCalls = resultRoot.Descendants(functionXName).Where(f => !f.Ancestors(functionXName).Any()); var evaluatedListOfInnerFunctions = nestedFunctionCalls.ToList(); if (!evaluatedListOfInnerFunctions.Any()) { break; } if (loopCount++ > 1000) { throw new InvalidOperationException("One or more function seems to be returning markup generating endless recursion. The following markup seems to generate the problem: " + evaluatedListOfInnerFunctions.First().ToString()); } var functionCallResults = new object[evaluatedListOfInnerFunctions.Count]; for (int i = 0; i < evaluatedListOfInnerFunctions.Count; i++) { XElement functionCallDefinition = evaluatedListOfInnerFunctions[i]; BaseRuntimeTreeNode runtimeTreeNode = FunctionTreeBuilder.Build(functionCallDefinition); functionCallResults[i] = runtimeTreeNode.GetValue(contextContainer); } ; for (int i = 0; i < evaluatedListOfInnerFunctions.Count; i++) { object embedableResult = contextContainer.MakeXEmbedable(functionCallResults[i]); if (embedableResult is XAttribute) { evaluatedListOfInnerFunctions[i].Parent.Add(embedableResult); evaluatedListOfInnerFunctions[i].Remove(); } else { evaluatedListOfInnerFunctions[i].ReplaceWith(embedableResult); } } } return(resultRoot); }
/// <exclude /> public static T Execute <T>(IFunction function, IDictionary <string, object> parameters, FunctionContextContainer functionContextContainer) { BaseRuntimeTreeNode node = BuildTree(function, parameters); return((T)node.GetValue(functionContextContainer)); }