Skip to content

Commit add0c54

Browse files
author
Pan Shao
committed
update
1 parent 1f6970c commit add0c54

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/dotnet/Azure.ClientSdk.Analyzers/Azure.ClientSdk.Analyzers/BannedAssembliesAnalyzer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void CheckType(ISymbolAnalysisContext context, ITypeSymbol type, ISymbol
3838
{
3939
if (BannedAssemblies.Contains(type.ContainingAssembly.Name))
4040
{
41-
if (type.Name != "Utf8JsonReader" && type.Name != "Utf8JsonWriter")
41+
if (!IsUtf8JsonReaderWriter(type))
4242
{
4343
context.ReportDiagnostic(Diagnostic.Create(Descriptors.AZC0014, symbol.Locations.First(), BannedAssembliesMessageArgs), symbol);
4444
}
@@ -89,5 +89,15 @@ static void CheckType(ISymbolAnalysisContext context, ITypeSymbol type, ISymbol
8989
break;
9090
}
9191
}
92+
93+
private static bool IsUtf8JsonReaderWriter(ITypeSymbol type)
94+
{
95+
return (type.Name == "Utf8JsonReader" || type.Name == "Utf8JsonWriter") && GetFullNamespace(type.ContainingNamespace) == "System.Text.Json";
96+
}
97+
98+
private static string GetFullNamespace(INamespaceSymbol type)
99+
{
100+
return type.ContainingNamespace.Name == "" ? type.Name : $"{GetFullNamespace(type.ContainingNamespace)}.{type.Name}";
101+
}
92102
}
93103
}

0 commit comments

Comments
 (0)