C
C#3y 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
Tvde13y ago
You could write your own analyzer
Angius
AngiusOP3y 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
333fred3y ago
You cannot Your only option is writing an analyzer
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server