Skip to main content

Convert to Tuple

  • 2 minutes to read
In This Article

Consolidates selected parameters into a Tuple object.

Convert to Tuple is a cascading refactoring. That is, the refactoring affects all method calls and method declarations in interfaces, base and descendant classes. For instance, if you apply the refactoring to the method declaration within an interface, it also changes the appropriate method declarations in all implementors and all calls to these methods.

#Availability

Available from the context menu or via shortcuts:

  • when the caret is on a method declaration or call, provided that it has more than one parameter;
  • when two or more parameters are selected in a method declaration or call.

Note

The refactoring is available for method declarations in interfaces, base and descendant classes, as well as for the declaration in the current class.

#Example

public void AddUser(string name, string familyName, int age)
{
    UserInfo uInfo = new UserInfo();
    uInfo.Name = name;
    uInfo.FamilyName = familyName;
    uInfo.Age = age;
    Users.Add(uInfo);
}
Public Sub AddUser(name As String, familyName As String, age As Integer)
    Dim uInfo As UserInfo = New UserInfo()
    uInfo.Name = name
    uInfo.FamilyName = familyName
    uInfo.Age = age
    Users.Add(uInfo)
End Sub

Result:

public void AddUser(Tuple<string, string, int> tuple)
{
    UserInfo uInfo = new UserInfo();
    uInfo.Name = tuple.Item1;
    uInfo.FamilyName = tuple.Item2;
    uInfo.Age = tuple.Item3;
    Users.Add(uInfo);
}
Public Sub AddUser(ByVal lTuple As Tuple(Of String, String, Integer))
    Dim uInfo As UserInfo = New UserInfo()
    uInfo.Name = lTuple.Item1
    uInfo.FamilyName = lTuple.Item2
    uInfo.Age = lTuple.Item3
    Users.Add(uInfo)
End Sub