public override object Invoke(Bindings bindings, ELContext context, Type returnType, Type[] paramTypes, object[] paramValues) { object @base = property.Prefix.Eval(bindings, context); if (@base == null) { throw new PropertyNotFoundException(LocalMessages.Get("error.property.base.null", property.Prefix)); } object method = property.GetProperty(bindings, context); if (method == null) { throw new PropertyNotFoundException(LocalMessages.Get("error.property.method.notfound", "null", @base)); } string name = bindings.Convert <string>(method, typeof(string)); paramValues = (object[])@params.Eval(bindings, context); context.PropertyResolved = false; object result = context.ELResolver.Invoke(context, @base, name, paramTypes, paramValues); if (!context.PropertyResolved) { throw new MethodNotFoundException(LocalMessages.Get("error.property.method.notfound", name, @base.GetType())); } // if (returnType != null && !returnType.isInstance(result)) { // should we check returnType for method invocations? // throw new MethodNotFoundException(LocalMessages.get("error.property.method.notfound", name, base.getClass())); // } return(result); }
public override object Invoke(Bindings bindings, ELContext context, Type returnType, Type[] paramTypes, object[] paramValues) { object @base = prefix.Eval(bindings, context); if (@base == null) { throw new PropertyNotFoundException(LocalMessages.Get("error.property.base.null", prefix)); } object property = GetProperty(bindings, context); if (property == null && strict) { throw new PropertyNotFoundException(LocalMessages.Get("error.property.method.notfound", "null", @base)); } string name = bindings.Convert <string>(property, typeof(string)); MethodInfo method = FindMethod(name, @base.GetType(), returnType, paramTypes); try { return(method.Invoke(@base, paramValues)); } catch (AccessViolationException) { throw new ELException(LocalMessages.Get("error.property.method.access", name, @base.GetType())); } catch (System.ArgumentException e) { throw new ELException(LocalMessages.Get("error.property.method.invocation", name, @base.GetType()), e); } catch (TargetInvocationException e) { throw new ELException(LocalMessages.Get("error.property.method.invocation", name, @base.GetType()), e.InnerException); } }
public override object Eval(Bindings bindings, ELContext context) { StringBuilder b = new StringBuilder(16); for (int i = 0; i < Cardinality; i++) { b.Append(bindings.Convert <string>(nodes[i].Eval(bindings, context), typeof(string))); } return(b.ToString()); }
/// <summary> /// evaluate and return the (optionally coerced) result. /// </summary> public object GetValue(Bindings bindings, ELContext context, Type type) { object value = Eval(bindings, context); if (type != null) { value = bindings.Convert <object>(value, type); } return(value); }
public override MethodInfo GetMethodInfo(Bindings bindings, ELContext context, Type returnType, Type[] paramTypes) { object @base = prefix.Eval(bindings, context); if (@base == null) { throw new PropertyNotFoundException(LocalMessages.Get("error.property.base.null", prefix)); } object property = GetProperty(bindings, context); if (property == null && strict) { throw new PropertyNotFoundException(LocalMessages.Get("error.property.method.notfound", "null", @base)); } string name = bindings.Convert <string>(property, typeof(string)); MethodInfo method = FindMethod(name, @base.GetType(), returnType, paramTypes); //return new MethodInfo(method.Name, method.ReturnType, paramTypes); return(method); }
public override object Eval(Bindings bindings, ELContext context) { bool?value = bindings.Convert <bool>(question.Eval(bindings, context), typeof(Boolean)); return(value.Value ? yes.Eval(bindings, context) : no.Eval(bindings, context)); }
public virtual object Eval(Bindings bindings, ELContext context, AstNode left, AstNode right) { bool?l = bindings.Convert <bool>(left.Eval(bindings, context), typeof(Boolean)); return(true.Equals(l) && bindings.Convert <bool>(right.Eval(bindings, context), typeof(Boolean))); }
public override object Invoke(Bindings bindings, ELContext context, Type returnType, Type[] paramTypes, object[] paramValues) { return(returnType == null ? value : bindings.Convert <string>(value, returnType)); }
/// <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)); }