Reporter | Angelina Elycheva (Angelina.Elycheva) |
---|---|
Created | Mar 17, 2016 1:21:29 PM |
Updated | Apr 20, 2018 12:42:09 PM |
Subsystem | Refactorings |
Assignee | Alisa Afonina (alisa.afonina) |
Priority | Normal |
State | Submitted |
Type | Bug |
Fix version | No Fix versions |
Affected versions | 2016.3 |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
C#6 introduces the Java-like "using static" clause which can make code a lot cleaner. Consider (using my RandomGenerators Nuget package):
using PeanutButter.RandomGenerators;
[TestFixture]
public class TestWibble
{
[Test]
public void Womble_ShouldNebulizeTheActuator()
{
var name = RandomValueGen.GetRandomString();
... // rest of test continues
}
}
which can now be written as:
using static PeanutButter.RandomGenerators.RandomValueGen;
[TestFixture]
public class TestWibble
{
[Test]
public void Womble_ShouldNebulizeTheActuator()
{
var name = GetRandomString();
... // rest of test continues
}
}
Which considerably cleans up test fixtures with lots of tests and lots of randomly generated input (as a very specific example). Now, if I had started this test fixture in another class file and use the Resharper refactoring to move to its own file, I'll find that all my usages of the statically-imported RandomValueGen are replaced with direct usages and my "using static" clause has been replaced with a simpler "using" clause.