I'm using CodeDom to generate code to be compiled later, and I've noticed that certain constructs create extra sets of parentheses. While I know they don't affect anything, they do look strange.
A sample of code that does it is this:
new CodeConditionStatement(
new CodeBinaryOperatorExpression(
new CodePropertyReferenceExpression(new CodePropertySetValueReferenceExpression(),
"Length"),
CodeBinaryOperatorType.GreaterThan,
new CodePrimitiveExpression(strLength)
),
new CodeThrowExceptionStatement(
new CodeObjectCreateExpression(typeof(ArgumentException),
new CodePrimitiveExpression("The string is too long"),
new CodePrimitiveExpression("value"))
)
)
This generates the following snippet:
if ((value.Length > 50)) {
throw new System.ArgumentException("The string is too long", "value");
}
Again, I know that the extra parentheses don't affect anything, but if I'm doing something wrong to do this, I'd like to know :)