示例#1
0
        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);
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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());
        }
示例#4
0
        /// <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);
        }
示例#5
0
        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);
        }
示例#6
0
        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));
        }
示例#7
0
            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)));
            }
示例#8
0
 public override object Invoke(Bindings bindings, ELContext context, Type returnType, Type[] paramTypes, object[] paramValues)
 {
     return(returnType == null ? value : bindings.Convert <string>(value, returnType));
 }
示例#9
0
 /// <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));
 }