Extract method doesn't detect variable assignment

public void Test(object x)
{
LinkedList list = head;
while(list!=null && list.Value!=x)
{
list = list.Next;
}
}

if I extract the code in while loop, I will get something like

public void Test(object x)
{
LinkedList list = head;
MethodX(list,x);
}

private MethodX(LinkedList list, object x)
{
while(list!=null && list.Value!=x)
{
list = list.Next;
}
}


but it actually should be

public void Test(object x)
{
LinkedList list = head;
MethodX(list,x);
}

private MethodX(ref LinkedList list, object x)
{
while(list!=null && list.Value!=x)
{
list = list.Next;
}
}

1 comment
Comment actions Permalink

Hello Nat,

Try using list after the loop - R# is recognising that you don't do anything
with it!

Ronnie

public void Test(object x)
{
LinkedList list = head;
while(list!=null && list.Value!=x)
{
list = list.Next;
}
}
if I extract the code in while loop, I will get something like

public void Test(object x)
{
LinkedList list = head;
MethodX(list,x);
}
private MethodX(LinkedList list, object x)
{
while(list!=null && list.Value!=x)
{
list = list.Next;
}
}
but it actually should be

public void Test(object x)
{
LinkedList list = head;
MethodX(list,x);
}
private MethodX(ref LinkedList list, object x)
{
while(list!=null && list.Value!=x)
{
list = list.Next;
}
}



0

Please sign in to leave a comment.