CodeNav icon indicating copy to clipboard operation
CodeNav copied to clipboard

Regions should take precedence over Interfaces, not the other way around.

Open Bergam64 opened this issue 3 years ago • 1 comments

Hello Samir,

I'd like to report a problem that has been there for ages: CodeNav always displays code structure with interfaces taking precedence over #regions. In order to correctly display the class structure, this should be the opposite.

Context:

  • CodeNav 2022 v8.9.40.
  • VS 2022 v17.2.6.
  • Sorting members by file order.

Repro with the following 2 files:

  • File "IMyService.cs":
namespace CodeNavInterfacesVsRegions
{
    public interface IMyService
    {
        void PublicMethod1();

        void PublicMethod2();
    }
}
  • File "MyService.cs":
namespace CodeNavInterfacesVsRegions
{
    public class MyService : IMyService
    {
        #region PublicMethod1

        public void PublicMethod1()
        {
            PrivateMethod11();
            PrivateMethod12();
        }

        private void PrivateMethod11()
        {
        }

        private void PrivateMethod12()
        {
        }

        #endregion

        #region PublicMethod2

        public void PublicMethod2()
        {
            PrivateMethod21();
            PrivateMethod22();
        }

        private void PrivateMethod21()
        {
        }

        private void PrivateMethod22()
        {
        }

        #endregion
    }
}

For class MyService, CodeNav displays this:

{} CodeNavInterfacesVsRegions
-------------------------------
 MyService : IMyService
 ------------------------------
 +----------------------------+
 | #PublicMethod1             |
 +----------------------------+
 | +-------------------------+|
 | | IMyService              ||
 | +-------------------------||
 | | PublicMethod1 ()        ||
 | | PublicMethod2 ()        ||  <-- This method (implementing interface) is not part of #region #PublicMethod1!
 | +-------------------------+|
 | PrivateMethod11 ()         |
 | PrivateMethod12 ()         |
 +----------------------------+

 +----------------------------+
 | #PublicMethod2 ()          |
 +----------------------------+
 | PrivateMethod21 ()         |
 | PrivateMethod22 ()         |
 +----------------------------+

But it should instead display this:

{} CodeNavInterfacesVsRegions
-------------------------------
 MyService : IMyService
 ------------------------------
 +----------------------------+
 | #PublicMethod1             |
 +----------------------------+
 | +-------------------------+|
 | | IMyService              ||
 | +-------------------------||
 | | PublicMethod1 ()        ||
 | +-------------------------+|
 | PrivateMethod11 ()         |
 | PrivateMethod12 ()         |
 +----------------------------+

 +----------------------------+
 | #PublicMethod2 ()          |
 +----------------------------+
 | +-------------------------+|  <-- Repeat block for interface implementation.
 | | IMyService              ||
 | +-------------------------||
 | | PublicMethod2 ()        ||  <-- This method (implementing interface) appears in the correct #region.
 | +-------------------------+|
 | PrivateMethod21 ()         |
 | PrivateMethod22 ()         |
 +----------------------------+

If you agree this is a bug, then please fix it, else add an option to control this precedence.

Thanks in advance.

Bergam64 avatar Jul 21 '22 07:07 Bergam64

This would be awesome!

BarzenX avatar Feb 02 '24 09:02 BarzenX