Added consistency in code formatting

2 spaces for tabs, outer element without indentation
namespace bit was incorrectly color formatted, fixed it by adding brackets
Indented continuation of a statement on the next line
Removed //... from class content, added them to method content
Fixed typos where void was used instead of class
Added empty lines between headers and code snippets
Added colons after headers
This commit is contained in:
RunninglVlan
2018-11-05 19:30:29 +02:00
committed by GitHub
parent 4e330f5aaa
commit 4399dcad84
+50 -13
View File
@@ -43,12 +43,12 @@ public class ClientActivity
// ... // ...
} }
} }
}
``` ```
***Why: consistent with the Microsoft's .NET Framework and easy to read.*** ***Why: consistent with the Microsoft's .NET Framework and easy to read.***
#### 3. Do not use Hungarian notation or any other type identification in identifiers #### 3. Do not use Hungarian notation or any other type identification in identifiers
```csharp ```csharp
// Correct // Correct
int counter; int counter;
@@ -60,7 +60,8 @@ public class ClientActivity
***Why: consistent with the Microsoft's .NET Framework and Visual Studio IDE makes determining types very easy (via tooltips). In general you want to avoid type indicators in any identifier.*** ***Why: consistent with the Microsoft's .NET Framework and Visual Studio IDE makes determining types very easy (via tooltips). In general you want to avoid type indicators in any identifier.***
#### 4. Do not use Screaming Caps for constants or readonly variables #### 4. Do not use Screaming Caps for constants or readonly variables:
```csharp ```csharp
// Correct // Correct
public static const string ShippingType = "DropShip"; public static const string ShippingType = "DropShip";
@@ -71,6 +72,7 @@ public class ClientActivity
***Why: consistent with the Microsoft's .NET Framework. Caps grap too much attention.*** ***Why: consistent with the Microsoft's .NET Framework. Caps grap too much attention.***
#### 5. Use meaningful names for variables. The following example uses seattleCustomers for customers who are located in Seattle: #### 5. Use meaningful names for variables. The following example uses seattleCustomers for customers who are located in Seattle:
```csharp ```csharp
var seattleCustomers = from cust in customers var seattleCustomers = from cust in customers
where cust.City == "Seattle" where cust.City == "Seattle"
@@ -80,6 +82,7 @@ public class ClientActivity
***Why: consistent with the Microsoft's .NET Framework and easy to read.*** ***Why: consistent with the Microsoft's .NET Framework and easy to read.***
#### 6. Avoid using Abbreviations. Exceptions: abbreviations commonly used as names, such as Id, Xml, Ftp, Uri. #### 6. Avoid using Abbreviations. Exceptions: abbreviations commonly used as names, such as Id, Xml, Ftp, Uri.
```csharp ```csharp
// Correct // Correct
UserGroup userGroup; UserGroup userGroup;
@@ -96,7 +99,8 @@ public class ClientActivity
***Why: consistent with the Microsoft's .NET Framework and prevents inconsistent abbreviations.*** ***Why: consistent with the Microsoft's .NET Framework and prevents inconsistent abbreviations.***
#### 7. Do use PascalCasing for abbreviations 3 characters or more (2 chars are both uppercase) #### 7. Do use PascalCasing for abbreviations 3 characters or more (2 chars are both uppercase):
```csharp ```csharp
HtmlHelper htmlHelper; HtmlHelper htmlHelper;
FtpTransfer ftpTransfer; FtpTransfer ftpTransfer;
@@ -106,6 +110,7 @@ public class ClientActivity
***Why: consistent with the Microsoft's .NET Framework. Caps would grap visually too much attention.*** ***Why: consistent with the Microsoft's .NET Framework. Caps would grap visually too much attention.***
#### 8. Do not use Underscores in identifiers. Exception: you can prefix private static variables with an underscore: #### 8. Do not use Underscores in identifiers. Exception: you can prefix private static variables with an underscore:
```csharp ```csharp
// Correct // Correct
public DateTime clientAppointment; public DateTime clientAppointment;
@@ -119,7 +124,8 @@ public class ClientActivity
***Why: consistent with the Microsoft's .NET Framework and makes code more natural to read (without 'slur'). Also avoids underline stress (inability to see underline).*** ***Why: consistent with the Microsoft's .NET Framework and makes code more natural to read (without 'slur'). Also avoids underline stress (inability to see underline).***
#### 9. Do use predefined type names instead of system type names like Int16, Single, UInt64, etc #### 9. Do use predefined type names instead of system type names like Int16, Single, UInt64, etc.
```csharp ```csharp
// Correct // Correct
string firstName; string firstName;
@@ -163,6 +169,7 @@ public class ClientActivity
***Why: consistent with the Microsoft's .NET Framework and easy to remember.*** ***Why: consistent with the Microsoft's .NET Framework and easy to remember.***
#### 12. Do prefix interfaces with the letter I. Interface names are noun (phrases) or adjectives. #### 12. Do prefix interfaces with the letter I. Interface names are noun (phrases) or adjectives.
```csharp ```csharp
public interface IShape public interface IShape
{ {
@@ -183,12 +190,10 @@ public class ClientActivity
// Located in Task.cs // Located in Task.cs
public partial class Task public partial class Task
{ {
//...
} }
// Located in Task.generated.cs // Located in Task.generated.cs
public partial class Task public partial class Task
{ {
//...
} }
``` ```
@@ -199,20 +204,27 @@ public class ClientActivity
```csharp ```csharp
// Examples // Examples
namespace Company.Product.Module.SubModule namespace Company.Product.Module.SubModule
{
}
namespace Product.Module.Component namespace Product.Module.Component
{
}
namespace Product.Layer.Module.Group namespace Product.Layer.Module.Group
{
}
``` ```
***Why: consistent with the Microsoft's .NET Framework. Maintains good organization of your code base.*** ***Why: consistent with the Microsoft's .NET Framework. Maintains good organization of your code base.***
#### 15. Do vertically align curly brackets: #### 15. Do vertically align curly brackets:
```csharp ```csharp
// Correct // Correct
class Program class Program
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
//...
} }
} }
``` ```
@@ -220,6 +232,7 @@ public class ClientActivity
***Why: Microsoft has a different standard, but developers have overwhelmingly preferred vertically aligned brackets.*** ***Why: Microsoft has a different standard, but developers have overwhelmingly preferred vertically aligned brackets.***
#### 16. Do declare all member variables at the top of a class, with static variables at the very top. #### 16. Do declare all member variables at the top of a class, with static variables at the very top.
```csharp ```csharp
// Correct // Correct
public class Account public class Account
@@ -237,9 +250,11 @@ public class ClientActivity
} }
} }
``` ```
***Why: generally accepted practice that prevents the need to hunt for variable declarations.*** ***Why: generally accepted practice that prevents the need to hunt for variable declarations.***
#### 17. Do use singular names for enums. Exception: bit field enums. #### 17. Do use singular names for enums. Exception: bit field enums.
```csharp ```csharp
// Correct // Correct
public enum Color public enum Color
@@ -262,9 +277,11 @@ public class ClientActivity
Left = 8 Left = 8
} }
``` ```
***Why: consistent with the Microsoft's .NET Framework and makes the code more natural to read. Plural flags because enum can hold multiple values (using bitwise 'OR').*** ***Why: consistent with the Microsoft's .NET Framework and makes the code more natural to read. Plural flags because enum can hold multiple values (using bitwise 'OR').***
#### 18. Do not explicitly specify a type of an enum or values of enums (except bit fields) #### 18. Do not explicitly specify a type of an enum or values of enums (except bit fields):
```csharp ```csharp
// Don't // Don't
public enum Direction : long public enum Direction : long
@@ -283,9 +300,11 @@ public class ClientActivity
West West
} }
``` ```
***Why: can create confusion when relying on actual types and values.*** ***Why: can create confusion when relying on actual types and values.***
#### 19. Do not use an "Enum" suffix in enum type names. #### 19. Do not use an "Enum" suffix in enum type names:
```csharp ```csharp
// Don't // Don't
public enum CoinEnum public enum CoinEnum
@@ -306,9 +325,11 @@ public class ClientActivity
Dollar Dollar
} }
``` ```
***Why: consistent with the Microsoft's .NET Framework and consistent with prior rule of no type indicators in identifiers.*** ***Why: consistent with the Microsoft's .NET Framework and consistent with prior rule of no type indicators in identifiers.***
#### 20. Do not use "Flag" or Flags" suffixes in enum type names. #### 20. Do not use "Flag" or "Flags" suffixes in enum type names:
```csharp ```csharp
// Don't // Don't
[Flags] [Flags]
@@ -331,26 +352,38 @@ public class ClientActivity
Left = 8 Left = 8
} }
``` ```
***Why: consistent with the Microsoft's .NET Framework and consistent with prior rule of no type indicators in identifiers.*** ***Why: consistent with the Microsoft's .NET Framework and consistent with prior rule of no type indicators in identifiers.***
#### 21. Do use suffix EventArgs at creation of the new classes comprising the information on event: #### 21. Do use suffix EventArgs at creation of the new classes comprising the information on event:
```csharp ```csharp
// Correct // Correct
public void BarcodeReadEventArgs : System.EventArgs public class BarcodeReadEventArgs : System.EventArgs
{
}
``` ```
***Why: consistent with the Microsoft's .NET Framework and easy to read.*** ***Why: consistent with the Microsoft's .NET Framework and easy to read.***
#### 22. Do name event handlers (delegates used as types of events) with the "EventHandler" suffix, as shown in the following example: #### 22. Do name event handlers (delegates used as types of events) with the "EventHandler" suffix, as shown in the following example:
```csharp ```csharp
public delegate void ReadBarcodeEventHandler(object sender, ReadBarcodeEventArgs e); public delegate void ReadBarcodeEventHandler(object sender, ReadBarcodeEventArgs e);
``` ```
***Why: consistent with the Microsoft's .NET Framework and easy to read.*** ***Why: consistent with the Microsoft's .NET Framework and easy to read.***
#### 23. Do not create names of parametres in methods (or constructors) which differ only the register: #### 23. Do not create names of parametres in methods (or constructors) which differ only by the register:
```csharp ```csharp
// Avoid // Avoid
private void MyFunction(string name, string Name) private void MyFunction(string name, string Name)
{
//...
}
``` ```
***Why: consistent with the Microsoft's .NET Framework and easy to read, and also excludes possibility of occurrence of conflict situations.*** ***Why: consistent with the Microsoft's .NET Framework and easy to read, and also excludes possibility of occurrence of conflict situations.***
#### 24. DO use two parameters named sender and e in event handlers. The sender parameter represents the object that raised the event. The sender parameter is typically of type object, even if it is possible to employ a more specific type. #### 24. DO use two parameters named sender and e in event handlers. The sender parameter represents the object that raised the event. The sender parameter is typically of type object, even if it is possible to employ a more specific type.
@@ -360,10 +393,14 @@ public class ClientActivity
***Why: consistent with the Microsoft's .NET Framework and consistent with prior rule of no type indicators in identifiers.*** ***Why: consistent with the Microsoft's .NET Framework and consistent with prior rule of no type indicators in identifiers.***
#### 25. Do use suffix Exception at creation of the new classes comprising the information on exception: #### 25. Do use suffix Exception at creation of the new classes comprising the information on exception:
```csharp ```csharp
// Correct // Correct
public void BarcodeReadException : System.Exception public class BarcodeReadException : System.Exception
{
}
``` ```
***Why: consistent with the Microsoft's .NET Framework and easy to read.*** ***Why: consistent with the Microsoft's .NET Framework and easy to read.***
## Offical Reference ## Offical Reference