dotnet / dotnet/sdk

CA2263 fix incorrectly drops all parameters after 'type' when 'params' follows

Open
#53,189 0 comments 1 reaction 0 assignees View on GitHub
Area-Microsoft.CodeAnalysis.NetAnalyzers untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug
CA2263: Prefer generic overload when type is known

When the non-generic overload has `(Type type, params T[]? args)` and the generic overload has `(params T[]? args)`, the fixer removes the `typeof(...)` argument but also incorrectly strips all remaining arguments instead of preserving them.

Used version of Microsoft.CodeAnalysis.NetAnalyzers: 10.0.103

### To Reproduce
```csharp
using System;

public class Demo
{
public void Run()
{
var activator = new Activator();

// CA2263 fixer converts this to 'activator.Create()' dropping "hello" and "world" arguments
_ = (MyClass)activator.Create(typeof(MyClass), "hello", "world");
}
}

public class MyClass
{
public MyClass(string[]) { }
}

public class Activator
{
public T Create(params string[]? args) => default!;
public object Create(Type type, params string[]? args) => default!;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.