/// <summary> /// Visits a unary expression /// </summary> /// <param name="expression">The expression</param> /// <exception cref="ArgumentNullException">Thrown when the input parameter is null</exception> public void Visit(UnaryExpression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } expression.Expression.Accept(this); if (result is int) { int param = (int)result; switch (expression.Type) { case UnaryExpressionType.Not: result = param != 0 ? 0 : 1; break; case UnaryExpressionType.BitNot: result = ~param; break; case UnaryExpressionType.Positive: result = +param; break; case UnaryExpressionType.Negative: result = -param; break; case UnaryExpressionType.Dereference: int value; int pointerValue; if (param == 1 || param == 0) { ValueExtractor ve = new ValueExtractor(); expression.Expression.Accept(ve); string expr = ve.Expression; if (context.TryResolveDereference(expr, out value, out pointerValue)) { result = value; } } else { IntPtr p = new IntPtr(param); // only supports 32bit pointer here. To support 64bit, too much work to do result = System.Runtime.InteropServices.Marshal.ReadInt32(p); } break; default: break; } } else if (result is string) { result = GetUnaryOperatorString(expression.Type) + result.ToString(); } }