private static bool IsSelfCalling(string functionName, BaseRuntimeTreeNode runtimeTreeNode) { if (runtimeTreeNode is FunctionParameterRuntimeTreeNode) { FunctionParameterRuntimeTreeNode functionParameterRuntimeTreeNode = runtimeTreeNode as FunctionParameterRuntimeTreeNode; if (functionParameterRuntimeTreeNode.GetHostedFunction().GetCompositeName() == functionName) { return(true); } return(IsSelfCalling(functionName, functionParameterRuntimeTreeNode.GetHostedFunction())); } if (runtimeTreeNode is BaseFunctionRuntimeTreeNode) { BaseFunctionRuntimeTreeNode functionRuntimeTreeNode = runtimeTreeNode as BaseFunctionRuntimeTreeNode; if (functionName == functionRuntimeTreeNode.GetCompositeName()) { return(true); } foreach (BaseParameterRuntimeTreeNode parameterRuntimeTreeNode in functionRuntimeTreeNode.Parameters) { if (IsSelfCalling(functionName, parameterRuntimeTreeNode)) { return(true); } } return(false); } return(false); }
public bool TrySerialize(Type objectToSerializeType, object objectToSerialize, IXmlSerializer xmlSerializer, out XElement serializedObject) { if (objectToSerializeType == null) { throw new ArgumentNullException("objectToSerializeType"); } serializedObject = null; if (typeof(BaseRuntimeTreeNode).IsAssignableFrom(objectToSerializeType)) { serializedObject = new XElement("BaseRuntimeTreeNode"); if (objectToSerialize != null) { BaseRuntimeTreeNode baseRuntimeTreeNode = objectToSerialize as BaseRuntimeTreeNode; serializedObject.Add(new XElement("Value", baseRuntimeTreeNode.Serialize())); } return(true); } else { return(false); } }
/// <exclude /> public void AddLazyParameter(string parameterName, BaseRuntimeTreeNode runtimeTreeNode, Type parameterType) { Verify.That(!_parameters.ContainsKey(parameterName), "Parameter '{0}' has already been assigned", parameterName); _parameters.Add(parameterName, new StoredParameterReturnValue { ValueObject = runtimeTreeNode, ValueType = parameterType, IsDefaultValue = false }); }
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); }
/// <summary> /// Fetches the tree node object of a parameter, if available. In contrast to the TryGetValue() function /// this will give you the 'value definition' rather than the result of calling it. /// </summary> /// <param name="parameterName">Name of the parameter</param> /// <param name="runtimeTreeNode"></param> /// <returns></returns> public bool TryGetParameterRuntimeTreeNode(string parameterName, out BaseRuntimeTreeNode runtimeTreeNode) { StoredParameterReturnValue storedParameterReturnValue; bool paramFound = _parameters.TryGetValue(parameterName, out storedParameterReturnValue); bool valueIsTreeNode = paramFound && storedParameterReturnValue.ValueObject is BaseRuntimeTreeNode; if (!valueIsTreeNode) { runtimeTreeNode = null; return(false); } runtimeTreeNode = (BaseRuntimeTreeNode)storedParameterReturnValue.ValueObject; return(true); }
/// <exclude /> public static T Execute <T>(IFunction function, IDictionary <string, object> parameters, FunctionContextContainer functionContextContainer) { BaseRuntimeTreeNode node = BuildTree(function, parameters); return((T)node.GetValue(functionContextContainer)); }