private bool MethodNameNotFound(MethodInformation methodInformation) { var invocationExpression = (InvocationExpressionSyntax)context.Node; var memberExpression = invocationExpression.Expression as MemberAccessExpressionSyntax; return(memberExpression?.Name?.Identifier.ValueText != methodInformation.MethodName); }
private bool QualifiedConstructorNameNotFound(MethodInformation methodInformation) { var objectCreationExpressionSyntax = (ObjectCreationExpressionSyntax)context.Node; var identifier = objectCreationExpressionSyntax.Type as QualifiedNameSyntax; return(identifier?.Right.ToString() != methodInformation.MethodName); }
private bool AbreviatedConstructorNameNotFound(MethodInformation methodInformation) { var objectCreationExpressionSyntax = (ObjectCreationExpressionSyntax)context.Node; var identifier = objectCreationExpressionSyntax.Type as IdentifierNameSyntax; return(identifier?.Identifier.ValueText != methodInformation.MethodName); }
public void AnalyzeConstrutor(MethodInformation methodInformation) { if (ConstructorNameNotFound(methodInformation) || MethodFullNameNotFound(methodInformation.MethodFullDefinition)) { return; } var argumentList = ((ObjectCreationExpressionSyntax)context.Node).ArgumentList; var arguments = GetArguments(argumentList); Execute(methodInformation, arguments, argumentList); }
public void AnalyzeMethod(MethodInformation methodInformation) { if (MethodNameNotFound(methodInformation) || MethodFullNameNotFound(methodInformation.MethodFullDefinition)) { return; } var argumentList = ((InvocationExpressionSyntax)context.Node).ArgumentList; var arguments = GetArguments(argumentList); Execute(methodInformation, arguments, argumentList); }
private void Execute(MethodInformation methodInformation, List <object> arguments, ArgumentListSyntax argumentList) { if (!argumentList.Arguments.Any()) { return; } try { methodInformation.MethodAction.Invoke(arguments); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } var diag = Diagnostic.Create(diagnosticDescriptor, argumentList.Arguments[methodInformation.ArgumentIndex].GetLocation(), ex.Message); context.ReportDiagnostic(diag); } }
private bool ConstructorNameNotFound(MethodInformation methodInformation) { return(AbreviatedConstructorNameNotFound(methodInformation) && QualifiedConstructorNameNotFound(methodInformation)); }