Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class SomeClient


[Theory]
[InlineData("public void JsonModelWriteCore(Utf8JsonWriter writer) {}")]
[InlineData("public void JsonModelCreateCore(ref Utf8JsonReader reader) {}")]
[InlineData("internal class Class: System.IProgress<JsonElement> { public void Report (JsonElement value) {} }")]
[InlineData("public void Report(string value) {}")]
public async Task AZC0014NotProducedForNonPublicApisOrAllowedTypes(string usage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ static void CheckType(ISymbolAnalysisContext context, ITypeSymbol type, ISymbol
{
if (BannedAssemblies.Contains(type.ContainingAssembly.Name))
{
context.ReportDiagnostic(Diagnostic.Create(Descriptors.AZC0014, symbol.Locations.First(), BannedAssembliesMessageArgs), symbol);
if (!IsUtf8JsonReaderWriter(type))
{
context.ReportDiagnostic(Diagnostic.Create(Descriptors.AZC0014, symbol.Locations.First(), BannedAssembliesMessageArgs), symbol);
}
}

if (namedTypeSymbol.IsGenericType)
Expand Down Expand Up @@ -86,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 namespaceSymbol)
{
return namespaceSymbol.ContainingNamespace.Name == "" ? namespaceSymbol.Name : $"{GetFullNamespace(namespaceSymbol.ContainingNamespace)}.{namespaceSymbol.Name}";
}
}
}