コード例 #1
0
        protected override void Run(IInvocationExpression element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
        {
            var methodIdentifier = element.GetSolution().GetComponent <IMoqMethodIdentifier>();

            if (!methodIdentifier.IsMoqCallbackMethod(element))
            {
                return;
            }

            var expectedTypeParameters = element.TypeArguments;

            if (expectedTypeParameters.Count == 0)
            {
                return;
            }

            var pointer = element.InvokedExpression;
            TreeNodeCollection <ICSharpArgument>?arguments = null;

            while (pointer != null && arguments == null && pointer.FirstChild is IInvocationExpression methodInvocation)
            {
                arguments = GetArguments(element.GetSolution(), methodInvocation);
                pointer   = methodInvocation.InvokedExpression;
            }

            if (arguments == null)
            {
                return;
            }

            var actualTypesParameters = arguments.Value.Select(x => x.Value.Type()).ToArray();
            var rule = element.GetPsiModule().GetTypeConversionRule();

            if (actualTypesParameters.Length <= 0)
            {
                return;
            }

            if (expectedTypeParameters.Count != actualTypesParameters.Length)
            {
                AddWarning(element, consumer);
            }
            else
            {
                for (var i = 0; i < expectedTypeParameters.Count; i++)
                {
                    var actualParameterType   = actualTypesParameters[i];
                    var expectedParameterType = expectedTypeParameters[i];

                    if (!actualParameterType.Equals(expectedParameterType) &&
                        !actualParameterType.IsImplicitlyConvertibleTo(expectedParameterType, rule))
                    {
                        AddWarning(element, consumer);
                    }
                }
            }
        }