2

Given the following abstract class:

public abstract class AbstractTest
{
    protected abstract void B();
    protected abstract void Aa();
    protected abstract void Ab();
    protected abstract void C();
}

In Visual Studio Code, if I select "Implement Abstract Class":

Implement Abstract Class example

The methods are automatically generated by ascending, alphabetic order:

Implement Abstract Class result


Does there exist a setting in VS Code that allows me to retain the order of the methods, in the order which I had originally defined them in?

budi
  • 6,351
  • 10
  • 55
  • 80

1 Answers1

3

Visual Studio and VS Code use the Roslyn language services to enable these kind of code fixes.

In order to figure out which members are missing from the implementation, Roslyn uses simple reflection on the base type.

Unfortunately, with reflection, there is no guaranteed member order at all. Compiled IL also does not have any member order, so it’s technically just not possible to get the member definition order from a compiled type. The only way would be to actually look at the source file; but that’s just not how Roslyn works.

poke
  • 369,085
  • 72
  • 557
  • 602