Skip to content

Instantly share code, notes, and snippets.

@controlflow
Last active January 21, 2019 20:06
Show Gist options
  • Save controlflow/1535b68072c13b6349bdab89d608697f to your computer and use it in GitHub Desktop.
Save controlflow/1535b68072c13b6349bdab89d608697f to your computer and use it in GitHub Desktop.
private static bool CheckHasValidRefOperands(
[NotNull] IConditionalTernaryExpression expression,
[NotNull] ICSharpExpression thenResult,
[NotNull] ICSharpExpression elseResult,
[NotNull] IHighlightingConsumer consumer)
{
var thenRefExpression = thenResult as IRefExpression;
var elseRefExpression = elseResult as IRefExpression;
if (elseRefExpression != null && thenRefExpression == null)
{
consumer.AddHighlighting(new RefConditionalNeedsTwoRefsError(expression, elseRefExpression));
return false;
}
if (elseRefExpression == null && thenRefExpression != null)
{
consumer.AddHighlighting(new RefConditionalNeedsTwoRefsError(expression, thenRefExpression));
return false;
}
return thenRefExpression != null;
}
private static bool CheckHasValidRefOperands(
[NotNull] IConditionalTernaryExpression expression,
[NotNull] ICSharpExpression thenResult,
[NotNull] ICSharpExpression elseResult,
[NotNull] IHighlightingConsumer consumer)
{
switch (thenResult, elseResult)
{
case (IRefExpression _, IRefExpression _):
return true;
case (IRefExpression thenRefExpression, _):
consumer.AddHighlighting(new RefConditionalNeedsTwoRefsError(expression, thenRefExpression));
return false;
case (_, IRefExpression elseRefExpression):
consumer.AddHighlighting(new RefConditionalNeedsTwoRefsError(expression, elseRefExpression));
return false;
default:
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment