coderushforroslyn-115476-refactoring-assistance-convert-to-tuple.md
Consolidates selected parameters into a Tuple object.
Note
Convert to Tuple is a cascading Refactoring. That means that the Refactoring affects all method calls and method declarations in interfaces, base and descendant classes. For instance, if you apply this Refactoring to the method declaration within an interface, it also changes the appropriate method declarations in all implementors and all calls to these methods.
Available in the following cases.
Place the caret on a method declaration.
Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
Select Convert to Tuple from the menu.
After execution, the Refactoring converts the parameters into a Tuple object and replaces all usages according to the change.
public class Library {
public Library() {
AddBook(new Tuple<string, string>("The Hitchhiker's Guide to the Galaxy", "D. Adams"));
AddBook(new Tuple<string, string>("The Hobbit, or There and Back Again", "J.R.R. Tolkien"));
}
private List<Book> shelf = new List<Book>();
public void AddBook(Tuple<string, string> tuple) {
shelf = shelf ?? new List<Book>();
shelf.Add(new Book(tuple.Item1, tuple.Item2));
}
}
Public Class Library
Public Sub New()
AddBook(New Tuple(Of String, String)("The Hitchhiker's Guide to the Galaxy", "D. Adams"))
AddBook(New Tuple(Of String, String)("The Hobbit, or There and Back Again", "J.R.R. Tolkien"))
End Sub
Private shelf As New List(Of Book)()
Public Sub AddBook(ByVal lTuple As Tuple(Of String, String))
shelf = If(shelf, New List(Of Book)())
shelf.Add(New Book(lTuple.Item1, lTuple.Item2))
End Sub
End Class
See Also