You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _pages/1000_ClassDesignGuidelines.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ With the exception of extension method containers, static classes very often lea
44
44
45
45
**Note:** If you really need that static class, mark it as static so that the compiler can prevent instance members and instantiating your class. This relieves you of creating an explicit private constructor.
46
46
47
-
### <aname="av1010"></a> Don't suppress compiler warnings using the new keyword (AV1010) 
47
+
### <aname="av1010"></a> Don't suppress compiler warnings using the `new` keyword (AV1010) 
48
48
49
49
Compiler warning [CS0114](https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0114) is issued when breaking [Polymorphism](http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming), one of the most essential object-orientation principles.
50
50
The warning goes away when you add the `new` keyword, but it keeps sub-classes difficult to understand. Consider the following two classes:
Copy file name to clipboardExpand all lines: _pages/1100_MemberDesignGuidelines.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Properties should be stateless with respect to other properties, i.e. there shou
19
19
20
20
**Exception:** Populating an internal cache or implementing [lazy-loading](http://www.martinfowler.com/eaaCatalog/lazyLoad.html) is a good exception.
21
21
22
-
### <aname="av1110"></a> Don't use mutual exclusive properties (AV1110) 
22
+
### <aname="av1110"></a> Don't use mutually exclusive properties (AV1110) 
23
23
24
24
Having properties that cannot be used at the same time typically signals a type that represents two conflicting concepts. Even though those concepts may share some of their behavior and states, they obviously have different rules that do not cooperate.
Avoid swallowing errors by catching non-specific exceptions, such as `Exception`, `SystemException`, and so on, in application code. Only top-level code, such as a last-chance exception handler, should catch a non-specific exception for logging purposes and a graceful shutdown of the application.
23
+
Avoid swallowing errors by catching non-specific exceptions, such as `Exception`, `SystemException`, and so on, in application code. Only top-level code, such as a last-chance exception handler, you should catch a non-specific exception for logging purposes and a graceful shutdown of the application.
24
24
25
25
### <aname="av1215"></a> Properly handle exceptions in asynchronous code (AV1215) 
26
26
When throwing or handling exceptions in code that uses `async`/`await` or a `Task` remember the following two rules:
@@ -50,7 +50,7 @@ Consider providing events that are raised when certain properties are changed. S
50
50
51
51
**Note:** If your class has many properties that require corresponding events, consider implementing the `INotifyPropertyChanged` interface instead. It is often used in the [Presentation Model](http://martinfowler.com/eaaDev/PresentationModel.html) and [Model-View-ViewModel](http://msdn.microsoft.com/en-us/magazine/dd419663.aspx) patterns.
52
52
53
-
### <aname="av1235"></a> Don't pass `null` as the `sender` argument when raising an event (AV1235) 
53
+
### <aname="av1235"></a> Don't pass `null` as the `sender` argument when raising an event (AV1235) 
54
54
55
55
Often an event handler is used to handle similar events from multiple senders. The sender argument is then used to get to the source of the event. Always pass a reference to the source (typically `this`) when raising the event. Furthermore don't pass `null` as the event data parameter when raising an event. If there is no event data, pass `EventArgs.Empty` instead of `null`.
56
56
@@ -81,7 +81,7 @@ Instead of casting to and from the object type in generic types or methods, use
81
81
}
82
82
}
83
83
84
-
### <aname="av1250"></a> Evaluate the result of a LINQ expression before returning it (AV1250) 
84
+
### <aname="av1250"></a> Evaluate the result of a LINQ expression before returning it (AV1250) 
85
85
86
86
Consider the following code snippet
87
87
@@ -99,6 +99,6 @@ Consider the following code snippet
99
99
100
100
Since LINQ queries use deferred execution, returning `query` will actually return the expression tree representing the above query. Each time the caller evaluates this result using a `foreach` cycle or similar, the entire query is re-executed resulting in new instances of `GoldMember` every time. Consequently, you cannot use the `==` operator to compare multiple `GoldMember` instances. Instead, always explicitly evaluate the result of a LINQ query using `ToList()`, `ToArray()` or similar methods.
101
101
102
-
### <aname="av1251"></a> Do not use `this` and `base` prefixes unless it is required (AV1251) 
102
+
### <aname="av1251"></a> Do not use `this` and `base` prefixes unless it is required (AV1251) 
103
103
104
104
In a class hierarchy, it is not necessary to know at which level a member is declared to use it. Refactoring derived classes is harder if that level is fixed in the code.
Copy file name to clipboardExpand all lines: _pages/1500_MaintainabilityGuidelines.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ sidebar:
9
9
### <aname="av1500"></a> Methods should not exceed 7 statements (AV1500) 
10
10
A method that requires more than 7 statements is simply doing too much or has too many responsibilities. It also requires the human mind to analyze the exact statements to understand what the code is doing. Break it down into multiple small and focused methods with self-explaining names, but make sure the high-level algorithm is still clear.
11
11
12
-
### <aname="av1501"></a> Make all members private and types internal sealed by default (AV1501) 
12
+
### <aname="av1501"></a> Make all members `private` and types `internal sealed` by default (AV1501) 
13
13
To make a more conscious decision on which members to make available to other classes, first restrict the scope as much as possible. Then carefully decide what to expose as a public member or type.
14
14
15
15
### <aname="av1502"></a> Avoid conditions with double negatives (AV1502) 
@@ -45,7 +45,7 @@ When using partial types and allocating a part per file, name each file after th
45
45
public partial class MyClass
46
46
{...}
47
47
48
-
### <aname="av1510"></a> Use using statements instead of fully qualified type names (AV1510) 
48
+
### <aname="av1510"></a> Use `using` statements instead of fully qualified type names (AV1510) 
49
49
Limit usage of fully qualified type names to prevent name clashing. For example, don't do this:
50
50
51
51
var list = new System.Collections.Generic.List<string>();
@@ -85,7 +85,7 @@ If the value of one constant depends on the value of another, attempt to make th
85
85
86
86
**Note:** An enumeration can often be used for certain types of symbolic constants.
87
87
88
-
### <aname="av1520"></a> Only use var when the type is very obvious (AV1520) 
88
+
### <aname="av1520"></a> Only use `var` when the type is very obvious (AV1520) 
89
89
Only use `var` as the result of a LINQ query, or if the type is very obvious from the same statement and using it would improve readability. So don't
90
90
91
91
var item = 3; // what type? int? uint? float?
@@ -120,7 +120,7 @@ Don't use confusing constructs like the one below:
120
120
121
121
(int a, int b) = M();
122
122
123
-
### <aname="av1523"></a> Favor Object and Collection Initializers over separate statements (AV1523) 
123
+
### <aname="av1523"></a> Favor object and collection initializers over separate statements (AV1523) 
124
124
Instead of:
125
125
126
126
var startInfo = new ProcessStartInfo("myapp.exe");
@@ -160,7 +160,7 @@ It is usually bad style to compare a `bool`-type expression to `true` or `false`
160
160
while (((condition == true) == true) == true) // where do you stop?
161
161
while (condition) // OK
162
162
163
-
### <aname="av1530"></a> Don't change a loop variable inside a for loop (AV1530) 
163
+
### <aname="av1530"></a> Don't change a loop variable inside a `for` loop (AV1530) 
164
164
Updating the loop variable within the loop body is generally considered confusing, even more so if the loop variable is modified in more than one place.
165
165
166
166
for (int index = 0; index < 10; ++index)
@@ -219,7 +219,7 @@ Add a descriptive comment if the `default` block is supposed to be empty. Moreov
219
219
}
220
220
}
221
221
222
-
### <aname="av1537"></a> Finish every if-else-if statement with an else-part (AV1537) 
222
+
### <aname="av1537"></a> Finish every `if`-`else`-`if` statement with an `else` clause (AV1537) 
223
223
For example:
224
224
225
225
void Foo(string answer)
@@ -239,10 +239,10 @@ For example:
239
239
}
240
240
}
241
241
242
-
### <aname="av1540"></a> Be reluctant with multiple return statements (AV1540) 
242
+
### <aname="av1540"></a> Be reluctant with multiple `return` statements (AV1540) 
243
243
One entry, one exit is a sound principle and keeps control flow readable. However, if the method body is very small and complies with guideline AV1500 then multiple return statements may actually improve readability over some central boolean flag that is updated at various points.
244
244
245
-
### <aname="av1545"></a> Don't use if-else statements instead of a simple (conditional) assignment (AV1545) 
245
+
### <aname="av1545"></a> Don't use an `if`-`else` construct instead of a simple (conditional) assignment (AV1545) 
246
246
Express your intentions directly. For example, rather than:
247
247
248
248
bool isPositive;
@@ -387,7 +387,7 @@ C# 4.0's named arguments have been introduced to make it easier to call COM comp
### <aname="av1561"></a> Don't declare signatures with more than three parameters (AV1561) 
390
+
### <aname="av1561"></a> Don't declare signatures with more than 3 parameters (AV1561) 
391
391
To keep constructors, methods, delegates and local functions small and focused, do not use more than three parameters. Do not use tuple parameters. Do not return tuples with more than two elements.
392
392
393
393
If you want to use more parameters, use a structure or class to pass multiple arguments, as explained in the [Specification design pattern](http://en.wikipedia.org/wiki/Specification_pattern).
0 commit comments