private void AnalyzeConstructorDeclaration(SyntaxNodeAnalysisContext context) { var declaration = (ConstructorDeclarationSyntax)context.Node; if (declaration.ExpressionBody == null) { BlockSyntax body = declaration.Body; ExpressionSyntax expression = UseExpressionBodiedMemberRefactoring.GetExpression(body); if (expression != null) { AnalyzeExpression(context, body, expression); } } }
private void AnalyzeLocalFunctionStatement(SyntaxNodeAnalysisContext context) { var localFunctionStatement = (LocalFunctionStatementSyntax)context.Node; if (localFunctionStatement.ExpressionBody == null) { BlockSyntax body = localFunctionStatement.Body; ExpressionSyntax expression = UseExpressionBodiedMemberRefactoring.GetExpression(body); if (expression != null) { AnalyzeExpression(context, body, expression); } } }
private void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context) { var method = (MethodDeclarationSyntax)context.Node; if (method.ExpressionBody == null) { BlockSyntax body = method.Body; ExpressionSyntax expression = UseExpressionBodiedMemberRefactoring.GetExpression(body); if (expression != null) { AnalyzeExpression(context, body, expression); } } }
private void AnalyzeAccessorDeclaration(SyntaxNodeAnalysisContext context) { var accessor = (AccessorDeclarationSyntax)context.Node; if (accessor.ExpressionBody == null && !accessor.AttributeLists.Any()) { BlockSyntax body = accessor.Body; ExpressionSyntax expression = UseExpressionBodiedMemberRefactoring.GetExpression(body); if (expression != null && expression.IsSingleLine()) { var accessorList = accessor.Parent as AccessorListSyntax; if (accessorList != null) { SyntaxList <AccessorDeclarationSyntax> accessors = accessorList.Accessors; if (accessors.Count == 1 && accessors.First().IsKind(SyntaxKind.GetAccessorDeclaration)) { if (accessorList.DescendantTrivia().All(f => f.IsWhitespaceOrEndOfLineTrivia())) { ReportDiagnostic(context, accessorList, expression); context.ReportToken(FadeOutDescriptor, accessor.Keyword); context.ReportBraces(FadeOutDescriptor, body); } return; } } if (accessor.DescendantTrivia().All(f => f.IsWhitespaceOrEndOfLineTrivia())) { ReportDiagnostic(context, body, expression); } } } }