Sei sulla pagina 1di 2

V1.

C# Style Sheet (based in StyleCop)


#region (SA1201, SA1203) access level (SA1202, SA1204) public internal protected internal protected private static non-static In this order Value types char bool byte short int long float double decimal Reference types string object data types 2 bytes NA 1 byte 2 bytes 4 bytes 8 bytes 4 bytes 8 bytes 16 bytes 2 bytes (general purpose)

1 of 2

CONSTANTS FIELDS CONSTRUCTORS FINALIZERS (destructors) EVENTS PROPERTIES METHODS FUNCTIONS PRIVATE FUNCTIONS PRIVATE METHODS

In this order

Jorge Serrano http://geeks.ms/blogs/jorge/

naming rules NO hungary notation YES camelCase PascalCase Class Constant Delegate Enum Event Field Function Generics Interface Method Namespace Parameters Project file Property Solution Source file Struct PascalCase PascalCase PascalCase PascalCase PascalCase camelCase PascalCase T + PascalCase I + PascalCase PascalCase PascalCase camelCase PascalCase PascalCase PascalCase PascalCase PascalCase Attributes Collections Enums Exceptions Resources name + Attribute name + Collection name + Type name + Exception PascalCase

V1.0

C# Style Sheet (based in StyleCop)


file organization Interfaces Classes Structs Delegates Enums One per file One per file One per file One per file One per file Namespace namespaces

2 of 2

xml document tags (frequently used) <summary> <remarks> <value> <para> <param> <return> <c> <exception> <see cref=> <seealso cref=> <example> <code> <![CDATA[ ]]> required required as needed optional as needed as needed as needed as needed optional optional as needed as needed as needed

Company.Product.Module.SubModule.Name

AssemblyInfo file AssemblyVersion CLSCompliant ComVisibleAttribute Assemblies Sign with strong name

manually true false

Jorge Serrano http://geeks.ms/blogs/jorge/

always (if apply)

coding general style rules Access modifiers Comments Comments Curly braces Events Lines Native data types Own reference Parameters Tabs Underscores UpperCase Variables Explicity always Only to explain Try use // or /// only One per line Check for null before Max. 80-120 characters int vs Int32, etc Use this inside them Recommended Max. 7 With size of 4 Avoid their use For 2 or fewer letters One per declaration Avoid Catch Custom Throw

exceptions Custom Exceptions Only to handle it Derive from Exception throw; vs throw e;

StyleCop general suppression rules Settings.StyleCop


SA1108 SA1119 SA1401 SA1505 SA1507 SA1508 SA1513 SA1515 SA1516 SA1623 SA1634 SA1642 SA1649

solution file

other recommendations Avoid sbyte, short, uint, and ulong (only for interop P/Invoke) Financial or money decimal type

Information: Based in StyleCop 4.5 RTM and my personal experience Optimized for Visual Studio 2010 and .NET Framework 4 v1.0 - July - 2011

References: StyleCop Rules v4.5 chm help file of Andy Reeves IDesign C# Coding Standard v2.4 of Juval Lowy

Potrebbero piacerti anche