C
C#2y ago
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)
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
}
public void Foo<T>()
{
_ctx.Set<T>(); // allowed
_ctx.Set<Product>(); // disallowed
}
is that even possible?
5 Replies
Tvde1
Tvde12y ago
You could write your own analyzer
Angius
Angius2y ago
Sure I could, but a) One already exists, so maybe it does already have this feature b) That would mean trying to make sense of the Roslyn APIs, and I'd rather learn ancient Sumerian in cursive
333fred
333fred2y ago
You cannot Your only option is writing an analyzer
Accord
Accord2y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server
More Posts