Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pan Shao committed Aug 9, 2024
1 parent 1f6970c commit 196171d
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -38,7 +38,7 @@ static void CheckType(ISymbolAnalysisContext context, ITypeSymbol type, ISymbol
{
if (BannedAssemblies.Contains(type.ContainingAssembly.Name))
{
if (type.Name != "Utf8JsonReader" && type.Name != "Utf8JsonWriter")
if (!IsUtf8JsonReaderWriter(type))
{
context.ReportDiagnostic(Diagnostic.Create(Descriptors.AZC0014, symbol.Locations.First(), BannedAssembliesMessageArgs), symbol);
}
Expand Down Expand Up @@ -89,5 +89,15 @@ static void CheckType(ISymbolAnalysisContext context, ITypeSymbol type, ISymbol
break;
}
}

private static bool IsUtf8JsonReaderWriter(ITypeSymbol type)
{
return (type.Name == "Utf8JsonReader" || type.Name == "Utf8JsonWriter") && GetFullNamespace(type.ContainingNamespace) == "System.Text.Json";
}

private static string GetFullNamespace(INamespaceSymbol type)
{
return type.ContainingNamespace.Name == "" ? type.Name : $"{GetFullNamespace(type.ContainingNamespace)}.{type.Name}";
}
}
}
}

0 comments on commit 196171d

Please sign in to comment.