Addressed nullable related warnings in Chapter 13.
MODIFY
src/Chapter13/Listing13.25.ExamingingAnExpressionTree.cs
src/Chapter13/Listing13.25.ExamingingAnExpressionTree.cs
public static void PrintNode(Expression expression,
int indent)
{
- if(expression is BinaryExpression)
- PrintNode(expression as BinaryExpression, indent);
+ if(expression is BinaryExpression binaryExpression)
+ PrintNode(binaryExpression, indent);
else
PrintSingle(expression, indent);
}
"", NodeToString(expression));
}
- private static string NodeToString(Expression expression)
- {
- switch(expression.NodeType)
- {
- case ExpressionType.Multiply:
- return "*";
- case ExpressionType.Add:
- return "+";
- case ExpressionType.Divide:
- return "/";
- case ExpressionType.Subtract:
- return "-";
- case ExpressionType.GreaterThan:
- return ">";
- case ExpressionType.LessThan:
- return "<";
- default:
- return expression.ToString() +
- " (" + expression.NodeType.ToString() + ")";
- }
- }
+ private static string NodeToString(Expression expression) =>
+ expression.NodeType switch
+ {
+ ExpressionType.Multiply => "*",
+ ExpressionType.Add => "+",
+ ExpressionType.Divide => "/",
+ ExpressionType.Subtract => "-",
+ ExpressionType.GreaterThan => ">",
+ ExpressionType.LessThan => "<",
+ _ => expression.ToString() +
+ " (" + expression.NodeType.ToString() + ")",
+ };
}
}
\ No newline at end of file

Addressed nullable related warnings in Chapter 13.