|
| 1 | +# Coding Guidelines |
| 2 | + |
| 3 | +## Definitions |
| 4 | + |
| 5 | +* [CamelCase](http://en.wikipedia.org/wiki/CamelCase) is a casing convention where the first letter is lower-case, words are not separated by any character but have their first letter capitalized. Example: <code>thisIsCamelCased</code>. |
| 6 | +* [PascalCase](http://c2.com/cgi/wiki?PascalCase) is a casing convention where the first letter of each word is capitalized, and no separating character is included between words. Example: <code>ThisIsPascalCased</code>. |
| 7 | + |
| 8 | +## C# coding conventions |
| 9 | + |
| 10 | +We should use the [Allman bracing style](http://en.wikipedia.org/wiki/Indent_style#Allman_style) for consistency. |
| 11 | + |
| 12 | +We are using the C# coding conventions described in this document as a guide, not everything in this doc is gospel and is open to debate: [C# Coding Guidelines](http://blogs.msdn.com/brada/articles/361363.aspx) with the following exceptions: |
| 13 | + |
| 14 | +* Each file should not start with a copyright notice. The ones at the root of the source tree will suffice. |
| 15 | +* Regions (#region) are not used. |
| 16 | +* using statements are on top of a file (outside of namespace {...}) |
| 17 | +* Use var only if you have an anonymous type or you can clearly tell what the type is from the right hand side of the expression |
| 18 | +* Member variables should always be private, public access should be provided by an encapsulated property. |
| 19 | + |
| 20 | +#### Naming |
| 21 | +Follow all .NET Framework Design Guidelines for both internal and external members. Highlights of these include: |
| 22 | +* Do use camelCasing for member variables, parameters and local variables |
| 23 | +* Do use PascalCasing for function, property, event, and class names |
| 24 | +* Do prefix interfaces names with “I” |
| 25 | +* Do __not__ use Hungarian notation |
| 26 | +* Do __not__ use a prefix for member variables (_, m_, s_, etc.). If you want to distinguish between local and member variables you should use “this.” |
| 27 | +* Do __not__ prefix enums, classes, or delegates with any letter |
| 28 | + |
| 29 | +Here is some sample code that follows these conventions. |
| 30 | + |
| 31 | + using System; |
| 32 | + namespace NuGet |
| 33 | + { |
| 34 | + public class ClassName |
| 35 | + { |
| 36 | + private List<SomeType> privateMember; |
| 37 | + |
| 38 | + public List<SomeType> SomeProperty |
| 39 | + { |
| 40 | + get |
| 41 | + { |
| 42 | + return privateMember; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + public string SomeAutoProperty { get; set; } |
| 47 | + |
| 48 | + public string SomeMethod(bool someCondition) |
| 49 | + { |
| 50 | + if (someCondition) |
| 51 | + { |
| 52 | + DoSomething(someArgument); |
| 53 | + } |
| 54 | + else |
| 55 | + { |
| 56 | + return someArray[10]; |
| 57 | + } |
| 58 | + |
| 59 | + switch (status) |
| 60 | + { |
| 61 | + case Status.Foo: |
| 62 | + return "Foo"; |
| 63 | + |
| 64 | + case Status.Bar: |
| 65 | + return "Bar"; |
| 66 | + |
| 67 | + default: |
| 68 | + return "Bar"; |
| 69 | + } |
| 70 | + return String.Empty; |
| 71 | + } |
| 72 | + |
| 73 | + private string AnotherMethod(){ |
| 74 | + return privateMember.Count; |
| 75 | + } |
| 76 | + } |
| 77 | + } |
0 commit comments