Created
December 12, 2016 12:20
-
-
Save controlflow/3dc8272d798939335a727e0bccb7ba05 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
foreach (var referenceExpression in codeBody.ThisAndDescendants<IReferenceExpression>()) | |
{ | |
var resolveResult = referenceExpression.Reference.Resolve(); | |
if (!resolveResult.ResolveErrorType.IsAcceptable) continue; | |
var declaredElement = resolveResult.Result.DeclaredElement; | |
var field = declaredElement as IField; | |
if (field != null) | |
{ | |
if (!field.IsReadonly && !field.IsConstant) | |
consumer.AddHighlighting(new NonReadonlyMemberInGetHashCodeWarning(referenceExpression, field)); | |
} | |
var property = declaredElement as IProperty; | |
if (property != null) | |
{ | |
if (property.IsAuto && property.Setter != null && referenceExpression.IsCSharp6Supported()) | |
consumer.AddHighlighting(new NonReadonlyMemberInGetHashCodeWarning(referenceExpression, property)); | |
} | |
var method = declaredElement as IMethod; | |
if (method.IsObjectGetHashCodeMethod() && referenceExpression.QualifierExpression.GetOperandThroughParenthesis() is IBaseExpression) | |
{ | |
consumer.AddHighlighting(new BaseObjectGetHashCodeCallInGetHashCodeWarning(referenceExpression)); | |
} | |
} |
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
foreach (var referenceExpression in codeBody.ThisAndDescendants<IReferenceExpression>()) | |
{ | |
var resolveResult = referenceExpression.Reference.Resolve(); | |
if (!resolveResult.ResolveErrorType.IsAcceptable) continue; | |
switch (resolveResult.Result.DeclaredElement) | |
{ | |
case IField field when !field.IsReadonly && !field.IsConstant: | |
consumer.AddHighlighting(new NonReadonlyMemberInGetHashCodeWarning(referenceExpression, field)); | |
break; | |
case IProperty property when property.IsAuto | |
&& property.Setter != null | |
&& referenceExpression.IsCSharp6Supported(): | |
consumer.AddHighlighting(new NonReadonlyMemberInGetHashCodeWarning(referenceExpression, property)); | |
break; | |
case IMethod method when method.IsObjectGetHashCodeMethod() | |
&& referenceExpression.QualifierExpression.GetOperandThroughParenthesis() is IBaseExpression: | |
consumer.AddHighlighting(new BaseObjectGetHashCodeCallInGetHashCodeWarning(referenceExpression)); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment