@@ -6,8 +6,10 @@ namespace StyleCop.Analyzers.DocumentationRules
66 using System ;
77 using System . Collections . Immutable ;
88 using System . Composition ;
9+ using System . Globalization ;
910 using System . Linq ;
1011 using System . Text . RegularExpressions ;
12+ using System . Threading ;
1113 using System . Threading . Tasks ;
1214 using Helpers ;
1315 using Microsoft . CodeAnalysis ;
@@ -57,7 +59,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
5759 context . RegisterCodeFix (
5860 CodeAction . Create (
5961 DocumentationResources . SA1642SA1643CodeFix ,
60- cancellationToken => GetTransformedDocumentAsync ( context . Document , root , xmlElementSyntax ) ,
62+ cancellationToken => GetTransformedDocumentAsync ( context . Document , root , xmlElementSyntax , cancellationToken ) ,
6163 nameof ( SA1642SA1643CodeFixProvider ) ) ,
6264 diagnostic ) ;
6365 }
@@ -74,11 +76,14 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
7476 }
7577 }
7678
77- private static Task < Document > GetTransformedDocumentAsync ( Document document , SyntaxNode root , XmlElementSyntax node )
79+ private static Task < Document > GetTransformedDocumentAsync ( Document document , SyntaxNode root , XmlElementSyntax node , CancellationToken cancellationToken )
7880 {
7981 var typeDeclaration = node . FirstAncestorOrSelf < BaseTypeDeclarationSyntax > ( ) ;
8082 var declarationSyntax = node . FirstAncestorOrSelf < BaseMethodDeclarationSyntax > ( ) ;
8183 bool isStruct = typeDeclaration . IsKind ( SyntaxKind . StructDeclaration ) ;
84+ var settings = document . Project . AnalyzerOptions . GetStyleCopSettings ( cancellationToken ) ;
85+ var culture = new CultureInfo ( settings . DocumentationRules . DocumentationCulture ) ;
86+ var resourceManager = DocumentationResources . ResourceManager ;
8287
8388 TypeParameterListSyntax typeParameterList ;
8489 ClassDeclarationSyntax classDeclaration = typeDeclaration as ClassDeclarationSyntax ;
@@ -94,35 +99,29 @@ private static Task<Document> GetTransformedDocumentAsync(Document document, Syn
9499 ImmutableArray < string > standardText ;
95100 if ( declarationSyntax is ConstructorDeclarationSyntax )
96101 {
102+ var typeKindText = resourceManager . GetString ( isStruct ? nameof ( DocumentationResources . TypeTextStruct ) : nameof ( DocumentationResources . TypeTextClass ) , culture ) ;
97103 if ( declarationSyntax . Modifiers . Any ( SyntaxKind . StaticKeyword ) )
98104 {
99- if ( isStruct )
100- {
101- standardText = ImmutableArray . Create ( SA1642ConstructorSummaryDocumentationMustBeginWithStandardText . StaticConstructorStandardText , " struct." ) ;
102- }
103- else
104- {
105- standardText = ImmutableArray . Create ( SA1642ConstructorSummaryDocumentationMustBeginWithStandardText . StaticConstructorStandardText , " class." ) ;
106- }
105+ standardText = ImmutableArray . Create (
106+ string . Format ( resourceManager . GetString ( nameof ( DocumentationResources . StaticConstructorStandardTextFirstPart ) , culture ) , typeKindText ) ,
107+ string . Format ( resourceManager . GetString ( nameof ( DocumentationResources . StaticConstructorStandardTextSecondPart ) , culture ) , typeKindText ) ) ;
107108 }
108109 else
109110 {
110111 // Prefer to insert the "non-private" wording for all constructors, even though both are considered
111112 // acceptable for private constructors by the diagnostic.
112113 // https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/413
113- if ( isStruct )
114- {
115- standardText = ImmutableArray . Create ( SA1642ConstructorSummaryDocumentationMustBeginWithStandardText . NonPrivateConstructorStandardText , " struct." ) ;
116- }
117- else
118- {
119- standardText = ImmutableArray . Create ( SA1642ConstructorSummaryDocumentationMustBeginWithStandardText . NonPrivateConstructorStandardText , " class." ) ;
120- }
114+ standardText = ImmutableArray . Create (
115+ string . Format ( resourceManager . GetString ( nameof ( DocumentationResources . NonPrivateConstructorStandardTextFirstPart ) , culture ) , typeKindText ) ,
116+ string . Format ( resourceManager . GetString ( nameof ( DocumentationResources . NonPrivateConstructorStandardTextSecondPart ) , culture ) , typeKindText ) ) ;
121117 }
122118 }
123119 else if ( declarationSyntax is DestructorDeclarationSyntax )
124120 {
125- standardText = SA1643DestructorSummaryDocumentationMustBeginWithStandardText . DestructorStandardText ;
121+ standardText =
122+ ImmutableArray . Create (
123+ resourceManager . GetString ( nameof ( DocumentationResources . DestructorStandardTextFirstPart ) , culture ) ,
124+ resourceManager . GetString ( nameof ( DocumentationResources . DestructorStandardTextSecondPart ) , culture ) ) ;
126125 }
127126 else
128127 {
0 commit comments