C#C
C#4y ago
6 replies
Angius

Banned Symbols Analyzer partial ban [Answered]

I currently ban
DbContext.Set<T>()
methods in my project using https://github.com/dotnet/roslyn-analyzers/tree/main/src/Microsoft.CodeAnalysis.BannedApiAnalyzers
M:Microsoft.EntityFrameworkCore.DbContext.Set``1
M:Microsoft.EntityFrameworkCore.DbContext.Set``1(System.String)

but I'd like to ban them only partially. Meaning, I want to disallow concrete types, but allow generic parameters. For example
public void Foo<T>()
{
    _ctx.Set<T>(); // allowed
    _ctx.Set<Product>(); // disallowed
}

is that even possible?
Was this page helpful?