Skip to content

When CodeNav is set to Sort by Order, some methods that are not part of an interface may be displayed out-of-order #164

@Bergam64

Description

@Bergam64

Hello Samir,

This is a follow-up issue for #140.

When CodeNav is set to Sort by Order, some methods that are not part of an interface may be displayed out-of-order.

Repro:

File IMyService.cs:

internal interface IMyService
{
    void PublicMethod1();

    void PublicMethod2();

    void PublicMethod3();
}

File MyService.cs:

namespace SomeNamespace;

internal sealed class MyService : IMyService
{
    private static void PrivateMethod0() // <-- Not part of an interface.
    {
    }

    public void PublicMethod1()
    {
    }

    private static void PrivateMethod1() // <-- Not part of an interface.
    {
    }

    public void PublicMethod2()
    {
    }

    public void PublicMethod3()
    {
    }

    internal void PrivateMethod3() // <-- Not part of an interface.
    {
    }
}

CodeNav displays this:

+---------------------------------+
| SomeNamespace                   |
+---------------------------------+
| +-----------------------------+ |
| | MyService : IMyService      | |
| +-----------------------------+ |
| | PrivateMethod0 ()           | |
| | +-------------------------+ | |
| | | IMyService              | | |
| | +-------------------------+ | |
| | | PublicMethod1 ()        | | |
| | | PublicMethod2 ()        | | |
| | | PublicMethod3 ()        | | |
| | +-------------------------+ | |
| | PrivateMethod1 ()           | | // <-- Wrong position (must be between 'PublicMethod1' and 'PublicMethod2').
| | PrivateMethod3 ()           | |
| +-----------------------------+ |
+---------------------------------+

But it should instead display this:

+---------------------------------+
| SomeNamespace                   |
+---------------------------------+
| +-----------------------------+ |
| | MyService : IMyService      | |
| +-----------------------------+ |
| | PrivateMethod0 ()           | |
| | +-------------------------+ | |
| | | IMyService              | | |
| | +-------------------------+ | |
| | | PublicMethod1 ()        | | |
| | +-------------------------+ | |
| | PrivateMethod1 ()           | |
| | +-------------------------+ | | // <-- Open interface block each time next method is part of an interface but previous method wasn't.
| | | IMyService              | | |
| | +-------------------------+ | |
| | | PublicMethod2 ()        | | |
| | | PublicMethod3 ()        | | | // <-- While current method is part of same interface as previous method, stay in same interface block.
| | +-------------------------+ | | // <-- Close interface block if next method is not part of same interface (or it's last method).
| | PrivateMethod3 ()           | |
| +-----------------------------+ |
+---------------------------------+

Note that if regions are involved, CodeNav display is correct.

Try with this file:

File MyService2.cs:

namespace SomeNamespace;

internal sealed class MyService2 : IMyService
{
    private static void PrivateMethod0() // <-- Not part of an interface.
    {
    }

    #region PublicMethod1

    public void PublicMethod1()
    {
    }

    private static void PrivateMethod1() // <-- Not part of an interface.
    {
    }

    #endregion

    public void PublicMethod2()
    {
    }

    #region PublicMethod3

    public void PublicMethod3()
    {
    }

    internal void PrivateMethod3() // <-- Not part of an interface.
    {

    #endregion
    }
}

CodeNav displays this:

+---------------------------------+
| SomeNamespace                   |
+---------------------------------+
| +-----------------------------+ |
| | MyService2 : IMyService     | |
| +-----------------------------+ |
| | PrivateMethod0 ()           | |
| | +-------------------------+ | |
| | | #PublicMethod1          | | |
| | +-------------------------+ | |
| | | +---------------------+ | | |
| | | | IMyService          | | | |
| | | +---------------------+ | | |
| | | | PublicMethod1 ()    | | | |
| | | +---------------------+ | | |
| | | PrivateMethod1 ()       | | |
| | +-------------------------+ | |
| | +-------------------------+ | |
| | | IMyService              | | |
| | +-------------------------+ | |
| | | PublicMethod2 ()        | | |
| | +-------------------------+ | |
| | +-------------------------+ | |
| | | #PublicMethod3          | | |
| | +-------------------------+ | |
| | | +---------------------+ | | |
| | | | IMyService          | | | |
| | | +---------------------+ | | |
| | | | PublicMethod3 ()    | | | |
| | | +---------------------+ | | |
| | | PrivateMethod3 ()       | | |
| | +-------------------------+ | |
| +-----------------------------+ |
+---------------------------------+

which is correct.

Context:

  • CodeNav 10.5.129.
  • VS 2026 Insiders [11619.145].

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions