C
Join ServerC#
help
Banned Symbols Analyzer partial ban [Answered]
AAngius11/7/2022
I currently ban
but I'd like to ban them only partially. Meaning, I want to disallow concrete types, but allow generic parameters. For example
is that even possible?
DbContext.Set<T>()
methods in my project using https://github.com/dotnet/roslyn-analyzers/tree/main/src/Microsoft.CodeAnalysis.BannedApiAnalyzersM: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?
TTvde111/7/2022
You could write your own analyzer
AAngius11/7/2022
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
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
OOrannis11/7/2022
You cannot
OOrannis11/7/2022
Your only option is writing an analyzer
AAngius11/7/2022
AAccord11/7/2022
✅ This post has been marked as answered!