public override SyntaxNode VisitVariableDeclarator(VariableDeclaratorSyntax node) { if (node.Initializer == null) { return(base.VisitVariableDeclarator(node)); } if (node.Parent is VariableDeclarationSyntax == false) { return(base.VisitVariableDeclarator(node)); } if (node.Parent.Parent is FieldDeclarationSyntax == false) { return(base.VisitVariableDeclarator(node)); } if ((node.Parent.Parent as FieldDeclarationSyntax).Modifiers.Any(x => x.ValueText == "const")) { return(base.VisitVariableDeclarator(node)); } var value = node.Initializer.Value; if ( !CheckOption((int)SimplifyClassFieldDeclaration.CleanupTypes.RemoveClassFieldsInitializerNull) && !CheckOption((int)SimplifyClassFieldDeclaration.CleanupTypes.RemoveClassFieldsInitializerLiteral) ) { return(base.VisitVariableDeclarator(node)); } if (value is LiteralExpressionSyntax) { var variableTypeNode = GetSystemTypeOfTypeNode((node.Parent as VariableDeclarationSyntax)); var valueObj = (value as LiteralExpressionSyntax).Token.Value; if (TypesMapItem.GetAllPredefinedTypesDic().ContainsKey(variableTypeNode)) { if (CheckOption((int)SimplifyClassFieldDeclaration.CleanupTypes.RemoveClassFieldsInitializerLiteral) == false) { return(base.VisitVariableDeclarator(node)); } var typeItem = TypesMapItem.GetAllPredefinedTypesDic()[variableTypeNode]; if ((typeItem.DefaultValue == null && valueObj != null) || (typeItem.DefaultValue != null && !typeItem.DefaultValue.Equals(valueObj))) { return(base.VisitVariableDeclarator(node)); } } else { if (CheckOption((int)SimplifyClassFieldDeclaration.CleanupTypes.RemoveClassFieldsInitializerNull) == false) { return(base.VisitVariableDeclarator(node)); } if (valueObj != null) { return(base.VisitVariableDeclarator(node)); } } if (isReportOnlyMode) { var lineSpan = node.GetFileLinePosSpan(); AddReport(new ChangesReport(node) { LineNumber = lineSpan.StartLinePosition.Line, Column = lineSpan.StartLinePosition.Character, Message = "Field initialize with \"= null;\" or \"= 0;\" can be removed", Generator = nameof(SimplifyClassFieldDeclarations) }); } node = node.WithInitializer(null).WithoutTrailingTrivia(); } return(base.VisitVariableDeclarator(node)); }