dotnet / roslynator

Roslynator is a set of code analysis tools for C#, powered by Roslyn.

Home Page:https://josefpihrt.github.io/docs/roslynator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RCS1102 False-positive when class is used as a type argument

bsal649 opened this issue · comments

Product and Version Used:
Roslynator.Analyzers 4.12.3

Steps to Reproduce:
Have a class such as below:

public class Create<TEntity, TOut> where TEntity : Common

And a usage of the class as seen here:

_ = services.AddValidatorsFromAssemblyContaining<Create<Foo, Bar>>();

Actual Behavior:
RCS1102 is raised. If the fixer is used, a C# error is raised at the usage:

'Create<Foo, Bar>': static types cannot be used as type arguments[CS0718]

Expected Behavior:
RCS1102 is not raised.

Could you provide full declaration of the "Create" class or at least the list of members? Does it contain only static members?

public class Create<TEntity, TDtoIn, TDtoOut> where TEntity : Common
{
    public class Command : IRequest<Result<Unit>>
    {
        public required List<TDtoIn> DtoInList { get; set; }
        public Func<TEntity, string>? TagStrategy { get; set; }
    }

    public class Handler : IRequestHandler<Command, Result<Unit>>
    {
        private readonly DataContext _context;
        private readonly IMapper _mapper;
        private readonly IUserAccessor _userAccessor;

        public Handler(DataContext context, IMapper mapper, IUserAccessor userAccessor)
        {
            _userAccessor = userAccessor;
            _mapper = mapper;
            _context = context;
        }

        public async Task<Result<Unit>> Handle(Command request, CancellationToken cancellationToken)
        {
            // endpoint logic
        }
    }
}

public class Common
{
    public Guid Id { get; set; } = Guid.NewGuid();
    public string? Tag { get; set; }
    public long UnixCreated { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
    public long? UnixUpdated { get; set; }
    public AppUser? UserCreated { get; set; }
    public AppUser? UserUpdated { get; set; }
    public Metadata? Metadata { get; set; }
}