private static void AnalyzePropertyGetterWithExpressionBody(PropertyDeclarationSyntax propertyNode, SyntaxNodeAnalysisContext context) { var getterExpression = propertyNode.ExpressionBody.Expression; var getterChildren = getterExpression.DescendantNodes(_ => true).ToImmutableArray(); if (getterChildren.Length > 1) { var getterWalker = new FindGetOrReadInvocationsWalker( getterExpression, context.SemanticModel); if (getterWalker.Invocation != null && getterChildren.Contains(getterWalker.Invocation)) { context.ReportDiagnostic(Diagnostic.Create( onlyUseCslaPropertyMethodsInGetSetRule, getterExpression.GetLocation())); } } }
private static void AnalyzePropertyGetterWithExpressionBody(PropertyDeclarationSyntax propertyNode, SyntaxNodeAnalysisContext context) { var getterExpression = propertyNode.ExpressionBody.Expression; var getterChildren = getterExpression.DescendantNodes(_ => true).ToImmutableArray(); if (getterChildren.Length > 1) { var getterWalker = new FindGetOrReadInvocationsWalker( getterExpression, context.SemanticModel); if (getterWalker.Invocation != null && getterChildren.Contains(getterWalker.Invocation)) { context.ReportDiagnostic(Diagnostic.Create( EvaluatePropertiesForSimplicityAnalyzer.onlyUseCslaPropertyMethodsInGetSetRule, getterExpression.GetLocation())); } } }
private static void AnalyzePropertyGetter(PropertyDeclarationSyntax propertyNode, SyntaxNodeAnalysisContext context) { var getter = propertyNode.AccessorList.Accessors.Single( _ => _.IsKind(SyntaxKind.GetAccessorDeclaration)).Body; var getterWalker = new FindGetOrReadInvocationsWalker(getter, context.SemanticModel); if(getterWalker.Invocation != null) { var getterStatements = getter.Statements; if (getterStatements.Count != 1) { context.ReportDiagnostic(Diagnostic.Create( EvaluatePropertiesForSimplicityAnalyzer.onlyUseCslaPropertyMethodsInGetSetRule, getter.GetLocation())); } else { var returnNode = getterStatements[0] as ReturnStatementSyntax; if(returnNode == null) { context.ReportDiagnostic(Diagnostic.Create( EvaluatePropertiesForSimplicityAnalyzer.onlyUseCslaPropertyMethodsInGetSetRule, getter.GetLocation())); } else { var invocation = returnNode.ChildNodes().SingleOrDefault( _ => _.IsKind(SyntaxKind.InvocationExpression)) as InvocationExpressionSyntax; if(invocation == null || invocation != getterWalker.Invocation) { context.ReportDiagnostic(Diagnostic.Create( EvaluatePropertiesForSimplicityAnalyzer.onlyUseCslaPropertyMethodsInGetSetRule, getter.GetLocation())); } } } } }
private static void AnalyzePropertyGetter(PropertyDeclarationSyntax propertyNode, SyntaxNodeAnalysisContext context) { var getter = propertyNode.AccessorList.Accessors.Single( _ => _.IsKind(SyntaxKind.GetAccessorDeclaration)).Body; var getterWalker = new FindGetOrReadInvocationsWalker(getter, context.SemanticModel); if (getterWalker.Invocation != null) { var getterStatements = getter.Statements; if (getterStatements.Count != 1) { context.ReportDiagnostic(Diagnostic.Create( EvaluatePropertiesForSimplicityAnalyzer.onlyUseCslaPropertyMethodsInGetSetRule, getter.GetLocation())); } else { var returnNode = getterStatements[0] as ReturnStatementSyntax; if (returnNode == null) { context.ReportDiagnostic(Diagnostic.Create( EvaluatePropertiesForSimplicityAnalyzer.onlyUseCslaPropertyMethodsInGetSetRule, getter.GetLocation())); } else { var invocation = returnNode.ChildNodes().SingleOrDefault( _ => _.IsKind(SyntaxKind.InvocationExpression)) as InvocationExpressionSyntax; if (invocation == null || invocation != getterWalker.Invocation) { context.ReportDiagnostic(Diagnostic.Create( EvaluatePropertiesForSimplicityAnalyzer.onlyUseCslaPropertyMethodsInGetSetRule, getter.GetLocation())); } } } } }