Goals Don’t add extension methods to the same namespace Avoid methods with more than 5 arguments (AV1561)
Prevent common mistakes and pitfalls as the extended class (AV1070) Do always check the result of an as operation (AV1570)
Prevent language constructs that can be Do evaluate the result of a LINQ expression before
misinterpreted
Promote object oriented development returning it (AV1076) Usage
Ensure that all source code has the same look-and- Do use C# types instead of the types from the System
feel
Maintainability namespace (AV2201)
Improve readability and reviewability
Avoid using names that can be mistaken with other Don’t hardcode strings that are presented to end-users
Design names (AV1501) (AV2206)
Don’t hide inherited members with the new keyword Do name a source file to the class it contains (AV1506) Do build with the highest warning level (AV2210)
(AV1010) Do limit the contents of a source code file to one class Avoid LINQ for simple expressions (AV2220)
It should be possible to treat a derived object as if it (AV1507) Do use Lambda expressions instead of delegates
were a base class object (AV1010) Don’t use "magic numbers" (AV1515) (AV2221)
Do allow properties to be set in any order (AV1015) Do use var only when the type is very obvious
Don’t create a constructor that does not yield a fully (AV1520)
initialized object (AV1020) Do initialize variables at the point of declaration, if
Don’t return an array (AV1025) possible (AV1521)
String and array properties should never return a null Favor Object and Collection Initializers over separate
reference (AV1027) statements (AV1523)
Provide a rich and meaningful exception message text Do use an enumeration instead of a list of strings if the
list of values is finite (AV1526) Important Note
(AV1040)
These coding guidelines are an extension to Visual
Don’t swallow errors by catching non-specific exceptions Do use a block with all flow control keywords, even if it is Studio 2008's Code Analysis functionalty, so make sure
(AV1042) empty (AV1535) you enable that for all you project. Check the full
document for more details.
Prefer throwing existing exceptions (AV1043) Do code every if-else if statement with an else-part
Do always check an event handler delegate for null (AV1537)
(AV1051) Avoid multiple return statements (AV1540)
Feedback
Do use a protected virtual method to raise each event Prefer conditional statements instead of simple if-else
This document has been compiled using many
(AV1052) constructs (AV1546) contributions from (ex) colleagues, sources from the
Do only implement casts that operate on the complete Do explicitly define the scope of a type or member Internet, and many years of developing in C#. If you
have questions, comments or suggestions, please let
object (AV1060) (AV1550)
us know by sending me an email at
Avoid casting to and from System.Object in code that Do implement the most complete overload of a method dennis.doomen@avivasolutions.nl. We will try to revise
uses generics (AV1062) or constructor and call it from the other overloaded and republish this document with new insights,
experiences and remarks on a regular basis.
methods or constructors (AV1551)