public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression) { IMember member = GetMember(memberReferenceExpression); if (member == null || member.IsStatic || member.FullName == "System.Nullable.HasValue") { base.VisitMemberReferenceExpression(memberReferenceExpression); return; } var parentFunction = ConstantNullCoalescingConditionIssue.GetParentFunctionNode(memberReferenceExpression); var analysis = GetAnalysis(parentFunction); var nullStatus = analysis.GetExpressionResult(memberReferenceExpression.Target); if (ProblematicNullStates.Contains(nullStatus)) { AddDiagnosticAnalyzer(new CodeIssue(memberReferenceExpression, ctx.TranslateString("Using member of null value will cause a NullReferenceException"))); } }
public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression) { IMember member = GetMember(memberReferenceExpression); if (member == null || member.IsStatic) { base.VisitMemberReferenceExpression(memberReferenceExpression); return; } var parentFunction = ConstantNullCoalescingConditionIssue.GetParentFunctionNode(memberReferenceExpression); var analysis = GetAnalysis(parentFunction); var nullStatus = analysis.GetExpressionResult(memberReferenceExpression.Target); if (ProblematicNullStates.Contains(nullStatus)) { //Depending on how reliable the null analysis turns out to be, we may also want to include PotentiallyNull here AddIssue(memberReferenceExpression, ctx.TranslateString("Using member of null value will cause a NullReferenceException")); } }