Created
November 10, 2016 00:32
-
-
Save controlflow/a9c163f0c1697c23ce76a9b284fa8304 to your computer and use it in GitHub Desktop.
switch2.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void RenderCaseLabel( | |
| [NotNull] ICSharpExpression conditionExpression, [NotNull] ISwitchCaseLabel switchCaseLabel, | |
| ref FactoryArgumentsBuilder builder, bool expressionIsPartOfDisjunction) | |
| { | |
| var guardClause = switchCaseLabel.Guard; | |
| var emitParentheses = expressionIsPartOfDisjunction || (guardClause != null && guardClause.Condition != null); | |
| if (emitParentheses) builder.Append('('); | |
| switch (switchCaseLabel.Pattern) | |
| { | |
| case IConstantPattern constantPattern: | |
| builder.Argument(conditionExpression).Append("==").Argument(constantPattern.Expression); | |
| break; | |
| case IDeclarationPattern declarationPattern: | |
| builder.Argument(conditionExpression).Append(" is ").Argument(declarationPattern); | |
| break; | |
| default: | |
| throw new ArgumentException(string.Format("Not supported pattern kind: {0}", pattern.GetType().Name)); | |
| } | |
| if (emitParentheses) builder.Append(')'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void RenderCaseLabel( | |
| [NotNull] ICSharpExpression conditionExpression, [NotNull] ISwitchCaseLabel switchCaseLabel, | |
| ref FactoryArgumentsBuilder builder, bool expressionIsPartOfDisjunction) | |
| { | |
| var guardClause = switchCaseLabel.Guard; | |
| var emitParentheses = expressionIsPartOfDisjunction || (guardClause != null && guardClause.Condition != null); | |
| if (emitParentheses) builder.Append('('); | |
| var pattern = switchCaseLabel.Pattern; | |
| var constantPattern = pattern as IConstantPattern; | |
| if (constantPattern != null) | |
| { | |
| builder.Argument(conditionExpression).Append("==").Argument(constantPattern.Expression); | |
| } | |
| else | |
| { | |
| var declarationPattern = pattern as IDeclarationPattern; | |
| if (declarationPattern != null) | |
| { | |
| builder.Argument(conditionExpression).Append(" is ").Argument(declarationPattern); | |
| } | |
| else | |
| { | |
| throw new ArgumentException(string.Format("Not supported pattern kind: {0}", pattern.GetType().Name)); | |
| } | |
| } | |
| if (emitParentheses) builder.Append(')'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment