Last active
February 26, 2017 17:59
-
-
Save controlflow/9bacea5d370b8b0d2aa48b48797e6648 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
[Pure] | |
private static bool IsFullyDiscardedDeconstructionExpression([NotNull] ITupleCreationExpression tupleCreationExpression) | |
{ | |
foreach (var tupleArgument in tupleCreationExpression.ArgumentsEnumerable) | |
{ | |
if (tupleArgument.NameIdentifier != null) return false; | |
if (tupleArgument.Colon != null) return false; | |
var tupleArgumentValue = tupleArgument.Value; | |
var referenceExpression = tupleArgumentValue as IReferenceExpression; | |
if (referenceExpression != null) | |
{ | |
if (referenceExpression.IsDiscardReferenceExpression()) continue; | |
return false; | |
} | |
var innerDeconstruction = tupleArgumentValue as ITupleCreationExpression; | |
if (innerDeconstruction != null) | |
{ | |
if (IsFullyDiscardedDeconstructionExpression(innerDeconstruction)) continue; | |
return false; | |
} | |
var declarationExpression = tupleArgumentValue as IDeclarationExpression; | |
if (declarationExpression != null) | |
{ | |
var designation = declarationExpression.Designation; | |
if (designation is IDiscardDesignation) continue; | |
var parenthesizedDesignation = designation as IParenthesizedVariableDesignation; | |
if (parenthesizedDesignation != null && IsFullyDiscardedParenthsizedDesignation(parenthesizedDesignation)) continue; | |
return false; | |
} | |
return false; | |
} | |
return true; | |
} |
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
[Pure] | |
private static bool IsFullyDiscardedDeconstructionExpression([NotNull] ITupleCreationExpression tupleCreationExpression) | |
{ | |
foreach (var tupleArgument in tupleCreationExpression.ArgumentsEnumerable) | |
{ | |
if (tupleArgument.NameIdentifier != null) return false; | |
if (tupleArgument.Colon != null) return false; | |
switch (tupleArgument.Value) | |
{ | |
case IReferenceExpression referenceExpression when referenceExpression.IsDiscardReferenceExpression(): | |
case ITupleCreationExpression innerDeconstruction when IsFullyDiscardedDeconstructionExpression(innerDeconstruction): | |
continue; | |
case IDeclarationExpression declarationExpression: | |
switch (declarationExpression.Designation) | |
{ | |
case IDiscardDesignation _: | |
case IParenthesizedVariableDesignation parenthesizedDesignation | |
when IsFullyDiscardedParenthsizedDesignation(parenthesizedDesignation): | |
continue; | |
default: | |
return false; | |
} | |
default: | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment