Exemplo n.º 1
0
 protected void CheckConstructorParameterSyntax(SyntaxNodeAnalysisContext c)
 {
     if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is IMethodSymbol ctor)
     {
         AbstractMethodParameterLookup <TArgumentSyntax> methodParamLookup = null;                          //Cache, there might be more of them
         foreach (var param in ctor.Parameters.Where(x => !x.IsParams && IsValidationDelegateType(x.Type))) //Validation for TryGetNonParamsSyntax, ParamArray/params and therefore array arguments are not inspected
         {
             methodParamLookup = methodParamLookup ?? CreateParameterLookup(c.Node, ctor);
             if (methodParamLookup.TryGetNonParamsSyntax(param, out var argument))
             {
                 TryReportLocations(new InspectionContext(c), ArgumentLocation(argument), ArgumentExpression(argument));
             }
         }
     }
 }
Exemplo n.º 2
0
            private void InspectTryGetSyntax
                (AbstractMethodParameterLookup <TArgumentSyntax> lookup, object expectedArguments, IMethodSymbol method)
            {
                lookup.TryGetSyntax(SpecialParameter, out var symbol).Should().Be(false);

                foreach (var parameter in method.Parameters)
                {
                    if (parameter.IsParams && lookup.TryGetSyntax(parameter, out var argumentList))
                    {
                        argumentList.Select(x => ExtractArgumentValue(x)).Should().BeEquivalentTo((IEnumerable)ExtractExpectedValue(expectedArguments, parameter.Name));
                    }
                    else if (!parameter.IsParams && lookup.TryGetNonParamsSyntax(parameter, out var argument))
                    {
                        ExtractArgumentValue(argument).Should().Be(ExtractExpectedValue(expectedArguments, parameter.Name));
                    }
                    else if (!parameter.IsOptional && !parameter.IsParams)
                    {
                        Assert.Fail($"TryGetSyntax missing {parameter.Name}");
                    } //Else it's OK
                }
            }