Skip to content

CS1501: Additional code fixes #769

@edneypitta

Description

@edneypitta

The analyzer will suggest more code fixes to error CS1501 about adding missing parameters.

The initial rules are:

  1. When there's only one reference to the method, it will suggest adding the parameter (in the call order).
  2. If there are two or more references to the method, it will suggest adding the parameter optionally with the default value of the type (adding the optional parameter at the end of the parameters list). If the method already exists, just change the order.

Rule 1

Case 1

Before:

static void Main(string[] args)
{
    A(5);
}

static void A()
{
}

After:

static void Main(string[] args)
{
    A(5);
}

static void A(int a)
{
}

Case 2

Before:

static void Main(string[] args)
{
    A("", 5);
}

static void A(int a)
{
}

After:

static void Main(string[] args)
{
    A("", 5);
}

static void A(string b, int a)
{
}

Rule 2

Case 1

Before:

static void Main(string[] args)
{
    A();
    A(5);
}

static void A()
{
}

After:

static void Main(string[] args)
{
    A();
    A(5);
}

static void A(int a = 0)
{
}

Case 2

Before:

static void Main(string[] args)
{
    A(5);
    A("", 5);
}

static void A(int a)
{
}

After:

static void Main(string[] args)
{
    A(5);
    A(5, "");
}

static void A(int a, string b = null)
{
}

Case 3

Before:

static void Main(string[] args)
{
    A(5);
    A("", 5);
}

static void A(int a)
{
}

static void A(int a, string b)
{
}

After:

static void Main(string[] args)
{
    A(5);
    A(5, "");
}

static void A(int a)
{
}

static void A(int a, string b)
{
}

Severity: Hidden
Category: Refactoring

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions