coderushforroslyn-115367-refactoring-assistance-boolean-to-enum.md
Use the Boolean to Enum Refactoring to convert two-state structures (method return types or method parameter types) into multiple-state structures. Enums have the following advantages.
Available when the caret is on a Boolean ( bool ) member, variable or method parameter.
Place the caret on a boolean member, variable or method parameter as shown in the code below.
Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
Select Boolean to Enum from the menu.
The Boolean to Enum Refactoring makes the following changes.
The result of the Refactoring execution is shown in the code below.
class TestClass {
private int TestMethod(TestMethodParam a) {
if (a == TestMethodParam.Success)
return 1000;
else
return 1024;
}
}
public enum TestMethodParam {
Success,
Failure
}
Public Class TestClass
Private Function TestMethod(ByVal a As TestMethodParam)
If (a = TestMethodParam.Success) Then
Return 1000
Else
Return 1024
End If
End Function
End Class
Public Enum TestMethodParam
Success
Failure
End Enum
See Also