private TreeNode EvaluateFunction(FunctionNode node) { object handler = null; TreeNode parent = node.Parent; TreeNode [] args = null; if (!functions.ContainsKey(node.Function)) { handler = ResolveFunction(node); if (handler == null) { throw new InvalidFunctionException(node.Function); } } else { handler = functions[node.Function]; } if (parent.Children[0] == node) { args = new TreeNode[parent.ChildCount - 1]; for (int i = 0; i < args.Length; i++) { args[i] = parent.Children[i + 1]; if (handler is MethodInfoContainer && !(handler as MethodInfoContainer).EvaluateVariables) { continue; } } } if (handler is FunctionNode) { return((handler as FunctionNode).Evaluate(this, args)); } else if (handler is SExpFunctionHandler) { return(((SExpFunctionHandler)handler)(this, args)); } else if (handler is MethodInfoContainer) { MethodInfoContainer container = (MethodInfoContainer)handler; return((TreeNode)container.MethodInfo.Invoke(container.Object, new object [] { args })); } else { throw new InvalidFunctionException(String.Format( "Unknown runtime method handler type {1}", handler.GetType())); } }
public void RegisterFunction(object o, MethodInfo method, string [] names, bool evaluateVariables) { var container = new MethodInfoContainer { MethodInfo = method, Object = o, EvaluateVariables = evaluateVariables }; foreach (string name in names) { if (functions.ContainsKey(name)) { functions.Remove(name); } functions.Add(name, container); } }
private void StaticallyCacheMethodInfosFor(Type[] wrappedTypes) { lock (MethodInfos) { foreach (var wrappedType in wrappedTypes) { if (MethodInfos.ContainsKey(wrappedType)) { return; } MethodInfos[wrappedType] = new MethodInfoContainer( wrappedType .GetMethods(BindingFlags.Instance | BindingFlags.Public) // TODO: handle method overloads, which this won't .Distinct(new MethodInfoComparer()) .ToArray() ); } } }
public void RegisterFunction(object o, MethodInfo method, string [] names, bool evaluateVariables) { MethodInfoContainer container = new MethodInfoContainer(); container.MethodInfo = method; container.Object = o; container.EvaluateVariables = evaluateVariables; foreach(string name in names) { if(functions.ContainsKey(name)) { functions.Remove(name); } functions.Add(name, container); } }