Inline Method (and delete)
- 2 minutes to read
In This Article
Replaces the current method call with the method’s body and deletes the method.
If the refactoring is called for method declaration, it replaces all method calls.
#Availability
Available from the context menus or via shortcuts:
- when the edit cursor or caret is on a method name within its call, provided that this call is the only call to this method.
- when the edit cursor or caret is on a method name within its declaration.
#Example
private List<UserInfo> GetUsersElderThen(int minAge)
{
int maxAge = int.MaxValue;
return FindUsers(minAge, maxAge);
}
private List<UserInfo> │FindUsers(int minAge, int maxAge)
{
List<UserInfo> result = new List<UserInfo>();
foreach (UserInfo uInfo in _Users)
{
if (uInfo.Age >= minAge && uInfo.Age <= maxAge)
result.Add(uInfo);
}
return result;
}
Private Function GetUsersElderThen(minAge As Integer) As List(Of UserInfo)
Dim maxAge As Integer = Integer.MaxValue
Return FindUsers(minAge, maxAge)
End Function
Private Function │FindUsers(minAge As Integer, maxAge As Integer) As List(Of UserInfo)
Dim result As List(Of UserInfo) = New List(Of UserInfo)
For Each uInfo In _Users
If uInfo.Age <= maxAge And uInfo.Age >= minAge Then
result.Add(uInfo)
End If
Next
Return result
End Function
Result:
private List<UserInfo> GetUsersElderThen(int minAge)
{
int maxAge = int.MaxValue;
List<UserInfo> result = new List<UserInfo>();
foreach (UserInfo uInfo in _Users)
{
if (uInfo.Age >= minAge && uInfo.Age <= maxAge)
result.Add(uInfo);
}
return result;
}
Private Function GetUsersElderThen(minAge As Integer) As List(Of UserInfo)
Dim maxAge As Integer = Integer.MaxValue
Dim result As List(Of UserInfo) = New List(Of UserInfo)()
For Each uInfo In _Users
If uInfo.Age <= maxAge And uInfo.Age >= minAge Then
result.Add(uInfo)
End If
Next
Return result
End Function