Skip to content

Commit 3132a7b

Browse files
committed
Create shared extension method IsExtensibleJsonObject
1 parent 33d2ae0 commit 3132a7b

4 files changed

Lines changed: 26 additions & 28 deletions

File tree

OpenStackNetAnalyzers/OpenStackNetAnalyzers/DocumentValueFromSummaryAnalyzer.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context)
5151
return;
5252

5353
INamedTypeSymbol declaringType = propertySymbol.ContainingType;
54-
if (!IsExtensibleJsonObject(declaringType))
54+
if (!declaringType.IsExtensibleJsonObject())
5555
return;
5656

5757
DocumentationCommentTriviaSyntax documentationTriviaSyntax = GetDocumentationCommentTriviaSyntax(syntax);
@@ -65,19 +65,6 @@ private void HandlePropertyDeclaration(SyntaxNodeAnalysisContext context)
6565
context.ReportDiagnostic(Diagnostic.Create(Descriptor, syntax.Identifier.GetLocation()));
6666
}
6767

68-
private bool IsExtensibleJsonObject(INamedTypeSymbol symbol)
69-
{
70-
while (symbol != null && symbol.SpecialType != SpecialType.System_Object)
71-
{
72-
if (string.Equals("global::OpenStack.ObjectModel.ExtensibleJsonObject", symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), StringComparison.Ordinal))
73-
return true;
74-
75-
symbol = symbol.BaseType;
76-
}
77-
78-
return false;
79-
}
80-
8168
internal static DocumentationCommentTriviaSyntax GetDocumentationCommentTriviaSyntax(SyntaxNode node)
8269
{
8370
if (node == null)

OpenStackNetAnalyzers/OpenStackNetAnalyzers/ImplementBuilderPatternAnalyzer.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private void HandleNamedType(SymbolAnalysisContext context)
4242
if (symbol.TypeKind != TypeKind.Class)
4343
return;
4444

45-
if (!IsExtensibleJsonObject(symbol))
45+
if (!symbol.IsExtensibleJsonObject())
4646
return;
4747

4848
foreach (var propertySymbol in symbol.GetMembers().OfType<IPropertySymbol>())
@@ -82,18 +82,5 @@ private void HandleNamedType(SymbolAnalysisContext context)
8282
}
8383
}
8484
}
85-
86-
private bool IsExtensibleJsonObject(INamedTypeSymbol symbol)
87-
{
88-
while (symbol != null && symbol.SpecialType != SpecialType.System_Object)
89-
{
90-
if (string.Equals("global::OpenStack.ObjectModel.ExtensibleJsonObject", symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), StringComparison.Ordinal))
91-
return true;
92-
93-
symbol = symbol.BaseType;
94-
}
95-
96-
return false;
97-
}
9885
}
9986
}

OpenStackNetAnalyzers/OpenStackNetAnalyzers/OpenStackNetAnalyzers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<Compile Include="PlaceholderDocumentationAnalyzer.cs" />
4848
<Compile Include="PlaceholderDocumentationCodeFix.cs" />
4949
<Compile Include="Properties\AssemblyInfo.cs" />
50+
<Compile Include="SdkTypeSymbolExtensions.cs" />
5051
<Compile Include="SpacingExtensions.cs" />
5152
<Compile Include="TypeSymbolExtensions.cs" />
5253
<Compile Include="XmlSyntaxFactory.cs" />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace OpenStackNetAnalyzers
2+
{
3+
using System;
4+
using Microsoft.CodeAnalysis;
5+
6+
internal static class SdkTypeSymbolExtensions
7+
{
8+
private const string FullyQualifiedExtensibleJsonObject = "global::OpenStack.ObjectModel.ExtensibleJsonObject";
9+
10+
public static bool IsExtensibleJsonObject(this INamedTypeSymbol symbol)
11+
{
12+
while (symbol != null && symbol.SpecialType != SpecialType.System_Object)
13+
{
14+
if (string.Equals(FullyQualifiedExtensibleJsonObject, symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), StringComparison.Ordinal))
15+
return true;
16+
17+
symbol = symbol.BaseType;
18+
}
19+
20+
return false;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)