Beispiel #1
0
        /// <summary>
        /// Evaluates the expression.
        /// </summary>
        /// <param name="context">Evaluation context.</param>
        /// <returns>Expression result.</returns>
        protected override object EvaluateNode(LogEventInfo context)
        {
            int parameterOffset = this.acceptsLogEvent ? 1 : 0;

            var callParameters = new object[this.MethodParameters.Count + parameterOffset];

            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < this.MethodParameters.Count; i++)
            {
                ConditionExpression ce = this.MethodParameters[i];
                callParameters[i + parameterOffset] = ce.Evaluate(context);
            }

            if (this.acceptsLogEvent)
            {
                callParameters[0] = context;
            }

            return(this.MethodInfo.DeclaringType.InvokeMember(
                       MethodInfo.Name,
                       BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public | BindingFlags.OptionalParamBinding,
                       null,
                       null,
                       callParameters
#if !SILVERLIGHT
                       , CultureInfo.InvariantCulture
#endif
                       ));
        }
Beispiel #2
0
        /// <summary>
        /// Evaluates the expression.
        /// </summary>
        /// <param name="context">Evaluation context.</param>
        /// <returns>Expression result.</returns>
        protected override object EvaluateNode(LogEventInfo context)
        {
            int parameterOffset   = _acceptsLogEvent ? 1 : 0;
            int parameterDefaults = _lateBoundMethodDefaultParameters != null ? _lateBoundMethodDefaultParameters.Length : 0;

            var callParameters = new object[MethodParameters.Count + parameterOffset + parameterDefaults];

            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < MethodParameters.Count; i++)
            {
                ConditionExpression ce = MethodParameters[i];
                callParameters[i + parameterOffset] = ce.Evaluate(context);
            }

            if (_acceptsLogEvent)
            {
                callParameters[0] = context;
            }

            if (_lateBoundMethodDefaultParameters != null)
            {
                for (int i = _lateBoundMethodDefaultParameters.Length - 1; i >= 0; --i)
                {
                    callParameters[callParameters.Length - i - 1] = _lateBoundMethodDefaultParameters[i];
                }
            }

            return(_lateBoundMethod(null, callParameters));  // Static-method so object-instance = null
        }
Beispiel #3
0
        public override object Evaluate(LogEventInfo context)
        {
            object v1 = par1.Evaluate(context);
            object v2 = par2.Evaluate(context);

            return(Compare(v1, v2, op));
        }
        private object[] GenerateCallParameters(LogEventInfo context)
        {
            int parameterOffset     = _acceptsLogEvent ? 1 : 0;
            int callParametersCount = _methodParameters.Length + parameterOffset + _lateBoundMethodDefaultParameters.Length;

            if (callParametersCount == 0)
            {
                return(ArrayHelper.Empty <object>());
            }

            var callParameters = new object[callParametersCount];

            if (_acceptsLogEvent)
            {
                callParameters[0] = context;
            }

            //Memory profiling pointed out that using a foreach-loop was allocating
            //an Enumerator. Switching to a for-loop avoids the memory allocation.
            for (int i = 0; i < _methodParameters.Length; i++)
            {
                ConditionExpression ce = _methodParameters[i];
                callParameters[i + parameterOffset] = ce.Evaluate(context);
            }

            if (_lateBoundMethodDefaultParameters.Length > 0)
            {
                for (int i = _lateBoundMethodDefaultParameters.Length - 1; i >= 0; --i)
                {
                    callParameters[callParameters.Length - i - 1] = _lateBoundMethodDefaultParameters[i];
                }
            }

            return(callParameters);
        }
Beispiel #5
0
        /// <summary>
        /// Evaluates the expression by evaluating <see cref="Left"/> and <see cref="Right"/> recursively.
        /// </summary>
        /// <param name="context">Evaluation context.</param>
        /// <returns>The value of the conjunction operator.</returns>
        public override object Evaluate(LogEventInfo context)
        {
            bool bval1 = (bool)Left.Evaluate(context);

            if (!bval1)
            {
                return(_boxedFalse);
            }

            bool bval2 = (bool)Right.Evaluate(context);

            if (!bval2)
            {
                return(_boxedFalse);
            }

            return(_boxedTrue);
        }
Beispiel #6
0
 public override object Evaluate(LogEventInfo context)
 {
     return(!((bool)expr.Evaluate(context)));
 }