Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bsal649 opened this issue May 27, 2024 · 2 comments
Open

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

bsal649 opened this issue May 27, 2024 · 2 comments

Comments

@bsal649
Copy link

bsal649 commented May 27, 2024

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.

@josefpihrt
Copy link
Collaborator

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

@bsal649
Copy link
Author

bsal649 commented Jun 3, 2024

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; }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants