//
// Prevent some common cases of invalid rewrites.
//
// Essentially, we don't want the rewritten node to be semantically
// bound by the factory, which may do the wrong thing. Instead we
// require derived classes to be explicit about what they want to do if
// types change.
//
private static UnaryExpression ValidateUnary(UnaryExpression before, UnaryExpression after)
{
if (before != after && before.Method == null)
{
if (after.Method != null)
{
throw Error.MustRewriteWithoutMethod(after.Method, nameof(VisitUnary));
}
// rethrow has null operand
if (before.Operand != null && after.Operand != null)
{
ValidateChildType(before.Operand.Type, after.Operand.Type, nameof(VisitUnary));
}
}
return(after);
}