PostProcessChangesAsync(Document document, CancellationToken cancellationToken)
{
document = await Simplifier.ReduceAsync(document, Simplifier.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
diff --git a/RefactoringEssentials/CodeRefactorings.CSharp.html b/RefactoringEssentials/CodeRefactorings.CSharp.html
index c1324518..5def2e9f 100644
--- a/RefactoringEssentials/CodeRefactorings.CSharp.html
+++ b/RefactoringEssentials/CodeRefactorings.CSharp.html
@@ -15,7 +15,7 @@
-->
Supported Refactorings
- 101 code refactorings for C#
+ 102 code refactorings for C#
- Adds another accessor (AddAnotherAccessorCodeRefactoringProvider)
- Add braces (AddBracesCodeRefactoringProvider)
@@ -54,6 +54,7 @@ Supported Refactorings
- Convert 'if' to 'return' (ConvertIfStatementToReturnStatementAction)
- Convert 'if' to 'switch' (ConvertIfStatementToSwitchStatementCodeRefactoringProvider)
- Convert implict to explicit implementation (ConvertImplicitToExplicitImplementationCodeRefactoringProvider)
+ - Convert instance to static method (ConvertInstanceToStaticMethodCodeRefactoringProvider)
- Convert string interpolation to 'string.Format' (ConvertInterpolatedStringToStringFormatCodeRefactoringProvider)
- Converts expression of lambda body to statement (ConvertLambdaBodyExpressionToStatementCodeRefactoringProvider)
- Converts statement of lambda body to expression (ConvertLambdaStatementToExpressionCodeRefactoringProvider)
diff --git a/RefactoringEssentials/RefactoringEssentials.csproj b/RefactoringEssentials/RefactoringEssentials.csproj
index eaba7dca..7c309cda 100644
--- a/RefactoringEssentials/RefactoringEssentials.csproj
+++ b/RefactoringEssentials/RefactoringEssentials.csproj
@@ -61,6 +61,7 @@
+
diff --git a/Tests/CSharp/CodeRefactorings/ConvertInstanceToStaticMethodCodeRefactoringTests.cs b/Tests/CSharp/CodeRefactorings/ConvertInstanceToStaticMethodCodeRefactoringTests.cs
new file mode 100644
index 00000000..552774ac
--- /dev/null
+++ b/Tests/CSharp/CodeRefactorings/ConvertInstanceToStaticMethodCodeRefactoringTests.cs
@@ -0,0 +1,279 @@
+using NUnit.Framework;
+using RefactoringEssentials.CSharp;
+using RefactoringEssentials.Tests.CSharp.CodeRefactorings;
+
+namespace RefactoringEssentials.Tests.CSharp
+{
+ ///
+ /// Tests for ConvertInstanceToStaticMethodCodeRefactoringProvider.
+ ///
+ [TestFixture]
+ public class ConvertInstanceToStaticMethodCodeRefactoringTests : CSharpCodeRefactoringTestBase
+ {
+ [Test]
+ public void MethodWithoutParameters1()
+ {
+ Test(@"
+class Foo
+{
+ void $Test()
+ {
+ int a = 0;
+ }
+}", @"
+class Foo
+{
+ static void Test(Foo instance)
+ {
+ int a = 0;
+ }
+}");
+ }
+
+ [Test]
+ public void MethodWithoutParameters2()
+ {
+ Test(@"
+class Foo
+{
+ public void $Test()
+ {
+ int a = 0;
+ }
+}", @"
+class Foo
+{
+ public static void Test(Foo instance)
+ {
+ int a = 0;
+ }
+}");
+ }
+
+ [Test]
+ public void MethodWithParameters()
+ {
+ Test(@"
+class Foo
+{
+ public void $Test(int b)
+ {
+ int a = 0;
+ }
+}", @"
+class Foo
+{
+ public static void Test(Foo instance, int b)
+ {
+ int a = 0;
+ }
+}");
+ }
+
+ [Test]
+ public void AlreadyStaticMethod()
+ {
+ TestWrongContext(@"
+class Foo
+{
+ public static void $Test(int b)
+ {
+ int a = 0;
+ }
+}");
+ }
+
+ [Test]
+ public void MethodUsingInstanceMember()
+ {
+ Test(@"
+class Foo
+{
+ int member;
+
+ void AnotherMethod(int a)
+ {
+ }
+
+ void $Test()
+ {
+ int a = 0;
+ member = a;
+ AnotherMethod(a);
+ }
+}", @"
+class Foo
+{
+ int member;
+
+ void AnotherMethod(int a)
+ {
+ }
+
+ static void Test(Foo instance)
+ {
+ int a = 0;
+ instance.member = a;
+ instance.AnotherMethod(a);
+ }
+}");
+ }
+
+ [Test]
+ public void MethodUsingInstanceMemberWithThis()
+ {
+ Test(@"
+class Foo
+{
+ int member;
+
+ void AnotherMethod(int a)
+ {
+ }
+
+ void $Test()
+ {
+ int a = 0;
+ this.member = a;
+ this.AnotherMethod(a);
+ }
+}", @"
+class Foo
+{
+ int member;
+
+ void AnotherMethod(int a)
+ {
+ }
+
+ static void Test(Foo instance)
+ {
+ int a = 0;
+ instance.member = a;
+ instance.AnotherMethod(a);
+ }
+}");
+ }
+
+ [Test]
+ public void RecursiveMethodCall()
+ {
+ Test(@"
+class Foo
+{
+ int member;
+
+ void $Test()
+ {
+ int a = 0;
+ Test();
+ }
+}", @"
+class Foo
+{
+ int member;
+
+ static void Test(Foo instance)
+ {
+ int a = 0;
+ Foo.Test(instance);
+ }
+}");
+ }
+
+ [Test]
+ public void RecursiveMethodCallWithThis()
+ {
+ Test(@"
+class Foo
+{
+ int member;
+
+ void $Test()
+ {
+ int a = 0;
+ this.Test();
+ }
+}", @"
+class Foo
+{
+ int member;
+
+ static void Test(Foo instance)
+ {
+ int a = 0;
+ Foo.Test(instance);
+ }
+}");
+ }
+
+ [Test]
+ public void MethodWithInternalReference()
+ {
+ Test(@"
+class Foo
+{
+ int member;
+
+ void AnotherMethod(int a)
+ {
+ Test();
+ }
+
+ void $Test()
+ {
+ }
+}", @"
+class Foo
+{
+ int member;
+
+ void AnotherMethod(int a)
+ {
+ Foo.Test(this);
+ }
+
+ static void Test(Foo instance)
+ {
+ }
+}");
+ }
+
+ [Test]
+ public void MethodWithExternalReference()
+ {
+ Test(@"
+class Foo
+{
+ public void $Test()
+ {
+ int a = 0;
+ }
+}
+
+class Foo2
+{
+ void Test(Foo foo)
+ {
+ foo.Test();
+ }
+}", @"
+class Foo
+{
+ public static void Test(Foo instance)
+ {
+ int a = 0;
+ }
+}
+
+class Foo2
+{
+ void Test(Foo foo)
+ {
+ Foo.Test(foo);
+ }
+}");
+ }
+ }
+}
+
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 14c29eca..26340638 100644
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -173,6 +173,7 @@
+