Back to Devexpress

Convert to Procedure

coderushforroslyn-117627-coding-assistance-code-providers-convert-to-procedure.md

latest1.3 KB
Original Source

Convert to Procedure

  • Aug 03, 2020

Purpose

This Code Provider is used to convert a function that returns a value of the appropriate type into a method that returns void. It is useful for instance when you have added a parameter passed into a method by reference and don’t need anything to be returned anymore.

Availability

Available when the caret is located on a non-void private method declaration. This method should have no references that use the returning value.

Usage

  1. Place the caret on a method’s name or type assuming that it returns a value of any type.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Convert to Procedure from the menu.

After execution, the Code Provider changes the method’s return type to void and removes the returned values from all return statements.

csharp
private void SayHello() {
    Console.WriteLine("Hello");
    return;
}
vb
Private Sub SayHello()
    Console.WriteLine("Hello")
    Return
End Sub

Note

This Code Provider is the opposite of Convert to Function