Last active
July 31, 2017 23:03
-
-
Save controlflow/aa2ef60a9502dd855cc3bdd9529b8c5e to your computer and use it in GitHub Desktop.
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
var orExpression = condition as IConditionalOrExpression; | |
if (orExpression != null) | |
{ | |
return ToSimpleConditions(leftOperand) && ToSimpleConditions(rightOperand); | |
} | |
var andExpression = condition as IConditionalAndExpression; | |
if (andExpression == null || myCSharpLanguageLevel < CSharpLanguageLevel.CSharp60) | |
return false; | |
var polyadicExpression = Polyadic<ICSharpExpression>.Build(condition, CSharpTokenType.ANDAND); | |
var firstExpression = polyadicExpression.Expressions.FirstOrDefault().GetOperandThroughParenthesisStrict(); | |
if (firstExpression == null | |
|| firstExpression is IConditionalAndExpression | |
|| firstExpression is IConditionalOrExpression) | |
return false; | |
var subexpression = polyadicExpression.Subexpression(1, polyadicExpression.Expressions.Count - 1); | |
return ToSimpleConditions(firstExpression, subexpression); |
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
switch (condition) | |
{ | |
case IConditionalOrExpression orExpression: | |
return ToSimpleConditions(leftOperand) && ToSimpleConditions(rightOperand); | |
case IConditionalAndExpression andExpression when myCSharpLanguageLevel => CSharpLanguageLevel.CSharp60: | |
var polyadicExpression = Polyadic<ICSharpExpression>.Build(condition, CSharpTokenType.ANDAND); | |
var firstExpression = polyadicExpression.Expressions.FirstOrDefault().GetOperandThroughParenthesisStrict(); | |
if (firstExpression == null | |
|| firstExpression is IConditionalAndExpression | |
|| firstExpression is IConditionalOrExpression) | |
return false; | |
var subexpression = polyadicExpression.Subexpression(1, polyadicExpression.Expressions.Count - 1); | |
return ToSimpleConditions(firstExpression, subexpression); | |
default: | |
return false; | |
} |
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
switch (condition) | |
{ | |
case IConditionalOrExpression orExpression: | |
return ToSimpleConditions(leftOperand) && ToSimpleConditions(rightOperand); | |
case IConditionalAndExpression andExpression when myCSharpLanguageLevel => CSharpLanguageLevel.CSharp60: | |
var polyadicExpression = Polyadic<ICSharpExpression>.Build(condition, CSharpTokenType.ANDAND); | |
switch (polyadicExpression.Expressions.FirstOrDefault().GetOperandThroughParenthesisStrict()) | |
{ | |
case null: | |
case IConditionalAndExpression _: | |
case IConditionalOrExpression _: | |
return false; | |
case var firstExpression: | |
var subexpression = polyadicExpression.Subexpression(1, polyadicExpression.Expressions.Count - 1); | |
return ToSimpleConditions(firstExpression, subexpression); | |
} | |
default: | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment