Advertisement
ivandrofly

Order of items in classes: Fields, Properties, Constructors,

Jul 28th, 2015
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. According to the StyleCop Rules Documentation the ordering is as follows.
  2.  
  3. Within a class, struct or interface: (SA1201 and SA1203)
  4.  
  5. Constant Fields
  6. Fields
  7. Constructors
  8. Finalizers (Destructors)
  9. Delegates
  10. Events
  11. Enums
  12. Interfaces
  13. Properties
  14. Indexers
  15. Methods
  16. Structs
  17. Classes
  18. Within each of these groups order by access: (SA1202)
  19.  
  20. public
  21. internal
  22. protected internal
  23. protected
  24. private
  25. Within each of the access groups, order by static, then non-static: (SA1204)
  26.  
  27. static
  28. non-static
  29. Within each of the static/non-static groups of fields, order by readonly, then non-readonly : (SA1214 and SA1215)
  30.  
  31. readonly
  32. non-readonly
  33. An unrolled list is 130 lines long, so I won't unroll it here. The methods part unrolled is:
  34.  
  35. public static methods
  36. public methods
  37. internal static methods
  38. internal methods
  39. protected internal static methods
  40. protected internal methods
  41. protected static methods
  42. protected methods
  43. private static methods
  44. private methods
  45. The documentation notes that if the prescribed order isn't suitable --- say, multiple interfaces are being implemented, and the interface methods and properties should be grouped together --- then use a partial class to group the related methods and properties together.
  46.  
  47. // Source http://stackoverflow.com/questions/150479/order-of-items-in-classes-fields-properties-constructors-methods
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement