How to reorder type members with Resharper?

前端 未结 8 488
名媛妹妹
名媛妹妹 2021-02-01 12:48

Typical scenario: a class that a lot of people have worked on. I\'d like to sort methods, properties, etc... in alphabetical order.

I\'d like to be able to do this wit

8条回答
  •  花落未央
    2021-02-01 13:05

    Two things: There is a known (but not heavily documented) condition where pre-compile conditionals (#if DEBUG for example) will stop type member reordering. http://youtrack.jetbrains.com/issue/RSRP-336643#tab=Comments In other words if you have #IF DEBUG then it won't reorder.

    I also recently noticed that in ReSharper 8.0.1 (and probably earlier versions) that the button to revert the XML template back to DEFAULT WITH REGIONS doesn't really have any statements to include #REGION grouping. So I took a StyleCop friendly template that includes sorting and added #REGION-ing to each type member. If you select CUSTOM TEMPLATE then paste in this XML it should work.

    
    
    
    
        
            
                
                
            
        
    
    
    
    
        
            
                
                
            
        
    
        
        
            
                
                    
                    
                        
                        
                        
                        
                    
                
            
        
        
        
        
        
            
                
                    
                    
                
            
            
                
            
        
    
    
    
    
    
    
        
        
            
                
                    
                    
                
            
            
                
                
            
            
        
    
    
        
        
            
                
                    
                    
                
            
    
            
                
                
                
                
                
            
            
        
    
        
        
            
                
            
            
                
                
            
            
        
    
        
        
            
                
            
            
                
                
            
            
        
    
        
        
            
                
            
            
                
                
            
            
        
    
    
        
        
            
                
            
    
            
                
                
            
            
        
    
        
        
            
                
                    
                    
                        
                    
                
            
            
                
                
                
                
                
                
            
            
        
    
        
        
            
                
            
            
                
                
                
                
                
                
            
            
        
    
        
        
            
                
                    
                        
                        
                        
                    
                    
                        
                    
                
            
            
                
                
                
                
                
                
            
            
        
    
        
        
    
        
        
            
                
            
            
                
                
                
                
                
                
            
            
        
    
    

提交回复
热议问题