Skip to content

Commit 5b9e2be

Browse files
authored
Merge pull request #43 from sharwell/property-markdown
Fix invalid cast converting Markdown code blocks
2 parents 0f87be9 + 9c083ab commit 5b9e2be

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

DocumentationAnalyzers/DocumentationAnalyzers.Test/RefactoringRules/DOC900UnitTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,30 @@ void Method<T2>() { }
225225
await VerifyCodeFixAsync(testCode, fixedCode);
226226
}
227227

228+
[Fact]
229+
[WorkItem(42, "https://github.com/DotNetAnalyzers/DocumentationAnalyzers/issues/42")]
230+
public async Task TestPropertyDocumentationWithCodeBlockAsync()
231+
{
232+
var testCode = @"
233+
class TestClass {
234+
///$$ <summary>
235+
/// Provide a `value`.
236+
/// </summary>
237+
int Property => 3;
238+
}
239+
";
240+
var fixedCode = @"
241+
class TestClass {
242+
///$$ <summary>
243+
/// Provide a <c>value</c>.
244+
/// </summary>
245+
int Property => 3;
246+
}
247+
";
248+
249+
await VerifyCodeFixAsync(testCode, fixedCode);
250+
}
251+
228252
private static async Task VerifyCodeFixAsync(string testCode, string fixedCode)
229253
{
230254
int iterations;

DocumentationAnalyzers/DocumentationAnalyzers/Helpers/SymbolExtensions.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ internal static class SymbolExtensions
1919
/// context of the specified <paramref name="symbol"/>; otherwise, <see langword="false"/>.</returns>
2020
public static bool HasAnyParameter(this ISymbol symbol, string name, StringComparer comparer)
2121
{
22-
if (symbol.Kind == SymbolKind.Method)
22+
if (symbol is IMethodSymbol methodSymbol)
2323
{
24-
var methodSymbol = (IMethodSymbol)symbol;
2524
return methodSymbol.Parameters.Any(parameter => comparer.Equals(parameter.Name, name));
2625
}
2726

@@ -40,18 +39,18 @@ public static bool HasAnyTypeParameter(this ISymbol symbol, string name, StringC
4039
{
4140
for (var currentSymbol = symbol; currentSymbol != null; currentSymbol = currentSymbol.ContainingSymbol)
4241
{
43-
switch (currentSymbol.Kind)
42+
switch (currentSymbol)
4443
{
45-
case SymbolKind.NamedType:
46-
if (((INamedTypeSymbol)symbol).TypeParameters.Any(parameter => comparer.Equals(parameter.Name, name)))
44+
case INamedTypeSymbol namedType:
45+
if (namedType.TypeParameters.Any(parameter => comparer.Equals(parameter.Name, name)))
4746
{
4847
return true;
4948
}
5049

5150
break;
5251

53-
case SymbolKind.Method:
54-
if (((IMethodSymbol)symbol).TypeParameters.Any(parameter => comparer.Equals(parameter.Name, name)))
52+
case IMethodSymbol method:
53+
if (method.TypeParameters.Any(parameter => comparer.Equals(parameter.Name, name)))
5554
{
5655
return true;
5756
}

0 commit comments

Comments
 (0)