public static BoundConstantExpression FoldConstantUnaryPrefixExpression( BindContext context, PrefixUnaryExpressionSyntax syntax, MethodSymbol unaryOperator, BoundExpression operand) { if (!operand.IsConstant) { return(null); } if (unaryOperator.IsOperator && unaryOperator.IsExtern) { object foldedValue; object operandValue = operand.ConstantValue.Value; switch (syntax.OperatorToken.Kind()) { case SyntaxKind.MinusToken: foldedValue = DynamicInvoke.UnaryNegate(operandValue); break; case SyntaxKind.ExclamationToken: foldedValue = DynamicInvoke.UnaryNot(operandValue); break; case SyntaxKind.TildeToken: foldedValue = DynamicInvoke.BitwiseNot(operandValue); break; default: return(null); } IConstantValue constantValue = (IConstantValue)Activator.CreateInstance(typeof(ConstantValue <>).MakeGenericType(foldedValue.GetType()), foldedValue); return(new BoundConstantExpression(constantValue, context.GetTypeSymbol(foldedValue.GetType()), syntax)); } return(null); }