place interfaces before classes

In a .cs file that contains multiple types how can I make R# place interfaced before classes when doing autocleanup. The classes interfaces are not nested and are part of the root namespace in that file. But still it doesn't reorder iterfaces before classes correctly. What is wrong with or missing in my XML config file:

<?xml version="1.0" encoding="utf-8" ?>

<Patterns xmlns="urn:shemas-jetbrains-com:member-reordering-patterns">

    <!--Do not reorder COM interfaces and structs marked by StructLayout attribute-->
    <Pattern>
        <Match>
            <Or Weight="100">
                <And>
                    <Kind Is="interface"/>
                    <Or>
                        <HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute"/>
                        <HasAttribute CLRName="System.Runtime.InteropServices.ComImport"/>
                    </Or>
                </And>
                <HasAttribute CLRName="System.Runtime.InteropServices.StructLayoutAttribute"/>
            </Or>
        </Match>
    </Pattern>

    <!--Special formatting of NUnit test fixture-->
    <Pattern RemoveAllRegions="true">
        <Match>
            <And Weight="100">
                <Kind Is="class"/>
                <HasAttribute CLRName="NUnit.Framework.TestFixtureAttribute" Inherit="true"/>
            </And>
        </Match>

        <!--Setup/Teardow-->
        <Entry>
            <Match>
                <And>
                    <Kind Is="method"/>
                    <Or>
                        <HasAttribute CLRName="NUnit.Framework.SetUpAttribute" Inherit="true"/>
                        <HasAttribute CLRName="NUnit.Framework.TearDownAttribute" Inherit="true"/>
                        <HasAttribute CLRName="NUnit.Framework.FixtureSetUpAttribute" Inherit="true"/>
                        <HasAttribute CLRName="NUnit.Framework.FixtureTearDownAttribute" Inherit="true"/>
                    </Or>
                </And>
            </Match>

        </Entry>

        <!--All other members-->
        <Entry/>

        <!--Test methods-->
        <Entry>
            <Match>
                <And Weight="100">
                    <Kind Is="method"/>
                    <HasAttribute CLRName="NUnit.Framework.TestAttribute" Inherit="false"/>
                </And>
            </Match>
            <Sort>
                <Name/>
            </Sort>
        </Entry>
    </Pattern>

    <!--Default pattern-->
    <Pattern RemoveAllRegions="true">

        <!--Fields and constants-->
        <Entry>
            <Match>
                <Or>
                    <Kind Is="field"/>
                    <Kind Is="constant"/>
                </Or>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Kind Order="constant"/>
                <Readonly/>
                <Static/>
                <Name/>
            </Sort>
        </Entry>

        <!--Constructors. Place static one first-->
        <Entry>
            <Match>
                <Kind Is="constructor"/>
            </Match>
            <Sort>
                <Static/>
                <Access Order="public internal protected-internal protected private" />
            </Sort>
        </Entry>

        <!--Destructors. Place static one first-->
        <Entry>
            <Match>
                <Kind Is="destructor"/>
            </Match>
            <Sort>
                <Static/>
                <Access Order="public internal protected-internal protected private" />
            </Sort>
        </Entry>

        <!--Delegates-->
        <Entry>
            <Match>
                <And Weight="100">
                    <Access Is="public"/>
                    <Kind Is="delegate"/>
                </And>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Name/>
            </Sort>
        </Entry>

        <!-- Events -->
        <Entry>
            <Match>
                <Kind Is="event"/>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Name/>
            </Sort>
        </Entry>

        <!--Enums-->
        <Entry>
            <Match>
                <Kind Is="enum"/>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Name/>
            </Sort>
        </Entry>

        <!--Interfaces-->
        <Entry>
            <Match>
                <Kind Is="interface"/>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Name/>
            </Sort>
        </Entry>

        <!--Properties-->
        <Entry>
            <Match>
                <And>
                    <Kind Is="property"/>
                    <Not>
                        <Kind Is="indexer"/>
                    </Not>
                </And>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Static/>
                <Abstract/>
                <Virtual/>
                <Override/>
                <Name/>
            </Sort>
        </Entry>

        <!--Indexers-->
        <Entry>
            <Match>
                <Kind Is="indexer"/>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Static/>
                <Abstract/>
                <Virtual/>
                <Override/>
                <Name/>
            </Sort>
        </Entry>

        <!--Methods-->
        <Entry>
            <Match>
                <And>
                    <Or>
                        <Kind Is="method"/>
                        <Kind Is="operator"/>
                        <HandlesEvent />
                    </Or>
                    <Not>
                        <Kind Is="destructor"/>
                    </Not>
                </And>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Static/>
                <Abstract/>
                <Virtual/>
                <Override/>
                <Name/>
            </Sort>
        </Entry>

        <!--Structs-->
        <Entry>
            <Match>
                <Kind Is="struct"/>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Name/>
            </Sort>
        </Entry>

        <!--Classes-->
        <Entry>
            <Match>
                <Kind Is="class"/>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Static/>
                <Name/>
            </Sort>
        </Entry>

        <!--all other members-->
        <Entry/>

        <!--nested types-->
        <Entry>
            <Match>
                <Kind Is="type"/>
            </Match>
            <Sort>
                <Access Order="public internal protected-internal protected private" />
                <Static/>
                <Abstract/>
                <Virtual/>
                <Override/>
                <Name/>
            </Sort>
        </Entry>
    </Pattern>

</Patterns>

1 comment
Comment actions Permalink

Hello,

As far as I know, the current member layouting engine does not operate outside
classes. Thus, there's no option to impose order on several top-level classes
in the same file.

Instead, R#5 has a refactoring (available on the context menu in Solution
Explorer) to place each type in a separate code file.


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0

Please sign in to leave a comment.