Ejemplo n.º 1
0
        private static void AnalyzeParameters(BaseAnalysisContext <ImmutableArray <IParameterSymbol> > context,
                                              [NotNull] ISymbol member, [NotNull] string memberName)
        {
            ImmutableArray <IParameterSymbol> parameters = context.Target;

            if (parameters.Length > MaxParameterCount)
            {
                ReportParameterCount(context.WithTarget(member), memberName, parameters.Length);
            }

            foreach (IParameterSymbol parameter in parameters)
            {
                if (parameter.Type.IsTupleType || TryGetSystemTupleElementCount(parameter.Type) != null)
                {
                    ReportTupleParameter(context.WithTarget(parameter), memberName, parameter.Name);
                }
            }
        }
Ejemplo n.º 2
0
        private static void AnalyzeReturnType(BaseAnalysisContext <ITypeSymbol> context, [NotNull] ISymbol member,
                                              [NotNull] string memberName)
        {
            int?elementCount = TryGetValueTupleElementCount(context.Target) ?? TryGetSystemTupleElementCount(context.Target);

            if (elementCount > 2)
            {
                ReportTupleReturn(context.WithTarget(member), memberName, elementCount.Value);
            }
        }
Ejemplo n.º 3
0
        private static void InnerAnalyzeMethod(BaseAnalysisContext <IMethodSymbol> context,
                                               [NotNull] DiagnosticCollector collector)
        {
            SyntaxNode bodySyntax = context.Target.TryGetBodySyntaxForMethod(context.CancellationToken);

            if (bodySyntax == null)
            {
                return;
            }

            AnalyzeParametersInMethod(context.WithTarget(context.Target.Parameters), bodySyntax, collector);
        }
Ejemplo n.º 4
0
        private static void AnalyzeParametersInMethod(BaseAnalysisContext <ImmutableArray <IParameterSymbol> > context,
                                                      [NotNull] SyntaxNode bodySyntax, [NotNull] DiagnosticCollector collector)
        {
            IGrouping <bool, IParameterSymbol>[] parameterGrouping = context.Target
                                                                     .Where(parameter => parameter.RefKind == RefKind.None && !parameter.IsSynthesized()).GroupBy(IsUserDefinedStruct)
                                                                     .ToArray();

            ICollection <IParameterSymbol> ordinaryParameters =
                parameterGrouping.Where(group => !group.Key).SelectMany(group => group).ToArray();

            if (ordinaryParameters.Any())
            {
                AnalyzeOrdinaryParameters(context.WithTarget(ordinaryParameters), bodySyntax, collector);
            }

            ICollection <IParameterSymbol> structParameters =
                parameterGrouping.Where(group => group.Key).SelectMany(group => group).ToArray();

            if (structParameters.Any())
            {
                AnalyzeStructParameters(context.WithTarget(structParameters), bodySyntax, collector);
            }
        }