Refactoring request: "Promote variable to parent scope/demote variable to child scope"
Open
Area-Refactorings
Feature Request
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 294
- Avg merge
- 2h 30m
- Merged PRs (30d)
- 4
Description
Essentially you have something like:
```csharp
if (someCondition)
{
var foo = bar();
}
```
and now you need to use `foo` outside of the conditional block, so you rewrite the code as:
```csharp
TypeOfFoo foo;
if (someCondition)
{
foo = bar();
}
```
Note that the RHS of the expression remains inside the conditional block; only the declaration moves. Doing this requires two steps: (1) moving the declaration (2) updating the declaration's type, and a refactoring that could do it in a single step would be most helpful. A complementary refactoring to go the other way (creating an anonymous scope to achieve this) would also probably be useful.
Contributor guide
Assessment
This issue has not been assessed yet.