Skip to content

Extract Method refactoring fails to capture inputs/outputs when unsafe blocks are included #4950

@Pilchie

Description

@Pilchie

From @AArnott:

using System;

class Program {
    static void Main(string[] args) {
        object value = args;

        // extract from here
        IntPtr p;
        unsafe
        {
            object t = value;
            p = IntPtr.Zero;
        }
        // to here

        Console.WriteLine(p);
    }
}

Open the C# console app in Dev14 and the Program.cs file.
Select lines 7 - 12 and execute the Extract Method command.

Expected
A new method that takes an object as a parameter and returns an IntPtr is created, and an invocation of that method replaces the selected lines that passes in "value" as the parameter and assigns the result to "IntPtr p".

Actual
A method is created that takes no parameters and returns void. Two compile errors are created by the refactoring as a result.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions