Element ordering details

Coordinator
May 15, 2012 at 12:46 PM
Edited May 31, 2012 at 9:46 AM

The 4 rules for this are:

  • <Rule Name="ElementsMustAppearInTheCorrectOrder" CheckId="SA1201">
  • <Rule Name="ElementsMustBeOrderedByAccess" CheckId="SA1202">
  • <Rule Name="ConstantsMustAppearBeforeFields" CheckId="SA1203">
  • <Rule Name="StaticElementsMustAppearBeforeInstanceElements" CheckId="SA1204">

First - it compares by ElementType – very straightforward – SA1201 if it’s wrong.

File = 0, Root = 1, ExternAliasDirective = 2, UsingDirective = 3, AssemblyAttribute = 4, Namespace = 5, Field = 6, Constructor = 7, Destructor = 8, Delegate = 9, Event = 10, Enum = 11, Interface = 12, Property = 13, Accessor = 14, Indexer = 15, Method = 16, Struct = 17, Class = 18, EnumItem = 19, ConstructorInitializer = 20, EmptyElement = 21,

Second – it compares AccessModifierType – SA1202 if it’s wrong – the exception here are static constructors (as they are private but must come first)

Public = 0, Internal = 1, ProtectedInternal = 2, Protected = 3, Private = 4, ProtectedAndInternal = 5

Third – it compares for statics/const/readonly

  • const
  • static readonly
  • static non-readonly
  • instance readonly
  • instance non-readonly
May 16, 2012 at 7:58 PM

Tried 4.7.22. Looks great! Thanks!