Microsoft.CodeAnalysis.BannedApiAnalyzers warn on parameter if used
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Brief description:**
I have a BannedSymbols.txt file with the following content
N:AutoMapper;Consider removing AutoMapper from your project. It will be commercial in v15
and expect that BannedApiAnalyzers will report any usage. Unfotunately it will report only when I call methods on the banned type, not the usage itself. E.g. if the banned type is used as constructor parameter or field then nothing will be reported.
**Languages applicable:**
C# (not tried in VB)
**Code example that the analyzer should report:**
```csharp
using AutoMapper;
public class Test
{
private readonly IMapper _mapper; // <-- should warn here
public Test(IMapper mapper) // <-- should warn here
{
_mapper = mapper;
}
public void T()
{
_mapper.Map(5); // here correclty warned
}
}
```
Contributor guide
Research direction
Reproduce the issue with BannedSymbols.txt and the C# example using AutoMapper.IMapper. Start by tracing BannedApiAnalyzers handling of type references, then verify that field and constructor-parameter usages produce warnings while the existing method-call warning remains. Done means the reported locations match the marked declarations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100