public override void LeaveUnaryExpression(UnaryExpression node)
{
if (node.Operator == UnaryOperatorType.Explode
|| node.Operator == UnaryOperatorType.AddressOf
|| node.Operator == UnaryOperatorType.Indirection
|| node.Operator == UnaryOperatorType.LogicalNot)
return;
if (null == node.Operand.ExpressionType)
return;
object operand = GetLiteralValue(node.Operand);
if (null == operand)
return;
Expression folded = null;
IType operandType = GetExpressionType(node.Operand);
if (TypeSystemServices.DoubleType == operandType || TypeSystemServices.SingleType == operandType)
{
folded = GetFoldedDoubleLiteral(node.Operator, Convert.ToDouble(operand));
}
else if (TypeSystemServices.IsIntegerNumber(operandType) || operandType.IsEnum)
{
folded = GetFoldedIntegerLiteral(node.Operator, Convert.ToInt64(operand));
}
if (null != folded)
{
folded.LexicalInfo = node.LexicalInfo;
folded.ExpressionType = GetExpressionType(node);
ReplaceCurrentNode(folded);
}
}