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))
                {
                    AddIssue(new CodeIssue(memberReferenceExpression,
                                           ctx.TranslateString("Using member of null value will cause a NullReferenceException")));
                }
            }
Пример #2
0
            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"));
                }
            }