public AstFunction(string name, int index, AstParameters @params, bool varargs) { this.name = name; this.index = index; this.@params = @params; this.varargs = varargs; }
protected internal AstFunction Function(string name, AstParameters @params) { if (functions.Count == 0) { functions = new List <IFunctionNode>(4); } AstFunction function = CreateAstFunction(name, functions.Count, @params); functions.Add(function); return(function); }
protected internal virtual AstMethod CreateAstMethod(AstProperty property, AstParameters @params) { return(new AstMethod(property, @params)); }
protected internal virtual AstFunction CreateAstFunction(string name, int index, AstParameters @params) { return(new AstFunction(name, index, @params, context.IsEnabled(Builder.Feature.VARARGS))); }
/// <summary> /// Invoke method. </summary> /// <param name="bindings"> </param> /// <param name="context"> </param> /// <param name="base"> </param> /// <param name="method"> </param> /// <returns> method result </returns> /// <exception cref="TargetInvocationException"> </exception> /// <exception cref="AccessViolationException"> </exception> protected internal virtual object Invoke(Bindings bindings, ELContext context, object @base, MethodInfo method) { Type[] types = method.GetParameters().Select(c => c.ParameterType).ToArray(); object[] @params = null; if (types.Length > 0) { @params = new object[types.Length]; //if (varargs && method.GetParameters().Any()) if (method.ContainsGenericParameters && method.GetParameters().Any()) { for (int i = 0; i < @params.Length - 1; i++) { object param = GetParam(i).Eval(bindings, context); if (param != null || types[i].IsPrimitive) { @params[i] = bindings.Convert <object>(param, types[i]); } } int varargIndex = types.Length - 1; Type varargType = types[varargIndex]; int length = ParamCount - varargIndex; object array = null; if (length == 1) { // special: eventually use argument as is object param = GetParam(varargIndex).Eval(bindings, context); if (param != null && param.GetType().IsArray) { if (types[varargIndex].IsInstanceOfType(param)) { array = param; } else { // coerce array elements //length = Array.GetLength(param); //array = Array.CreateInstance(varargType, length); //for (int i = 0; i < length; i++) //{ // object elem = Array.Get(param, i); // if (elem != null || varargType.IsPrimitive) // { // ((System.Array)array).SetValue(bindings.Convert(elem, varargType), i); // } //} } } else { // single element array array = Array.CreateInstance(varargType, 1); if (param != null || varargType.IsPrimitive) { ((System.Array)array).SetValue(bindings.Convert <object>(param, varargType), 0); } } } else { array = Array.CreateInstance(varargType, length); for (int i = 0; i < length; i++) { object param = GetParam(varargIndex + i).Eval(bindings, context); if (param != null || varargType.IsPrimitive) { ((System.Array)array).SetValue(bindings.Convert <object>(param, varargType), i); } } } @params[varargIndex] = array; } else { for (int i = 0; i < @params.Length; i++) { object param = GetParam(i).Eval(bindings, context); if (param != null || types[i].IsPrimitive) { @params[i] = bindings.Convert <object>(param, types[i]); } } } } return(method.Invoke(@base, @params)); }
public AstFunction(string name, int index, AstParameters @params) : this(name, index, @params, false) { }
public AstMethod(AstProperty property, AstParameters @params) { this.property = property; this.@params = @params; }