Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AV2202 #144

Merged
merged 1 commit into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions _pages/2200_FrameworkGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,52 @@ For instance, use `object` instead of `Object`, `string` instead of `String`, an

**Exception:** When referring to static members of those types, it is custom to use the full CLS name, e.g. `Int32.Parse()` instead of `int.Parse()`. The same applies to members that need to specify the type they return, e.g. `ReadInt32`, `GetUInt16`.

### <a name="av2202"></a> Prefer language syntax over explicit calls to underlying implementations (AV2202) ![](/assets/images/1.png)
Language syntax makes code more concise. The abstractions make later refactorings easier (and sometimes allow for extra optimizations).

Prefer:

(string, int) tuple = ("", 1);

rather than:

ValueTuple<string, int> tuple = new ValueTuple<string, int>("", 1);

Prefer:

DateTime? startDate;

rather than:

Nullable<DateTime> startDate;

Prefer:

if (startDate != null) ...

rather than:

if (startDate.HasValue) ...

Prefer:

if (startDate > DateTime.Now) ...

rather than:

if (startDate.HasValue && startDate.Value > DateTime.Now) ...

Prefer:

(DateTime startTime, TimeSpan duration) tuple1 = GetTimeRange();
(DateTime startTime, TimeSpan duration) tuple2 = GetTimeRange();

if (tuple1 == tuple2) ...

rather than:

if (tuple1.startTime == tuple2.startTime && tuple1.duration == tuple2.duration) ...

### <a name="av2207"></a> Don't hard-code strings that change based on the deployment (AV2207) ![](/assets/images/3.png)
Examples include connection strings, server addresses, etc. Use `Resources`, the `ConnectionStrings` property of the `ConfigurationManager` class, or the `Settings` class generated by Visual Studio. Maintain the actual values into the `app.config` or `web.config` (and most definitely not in a custom configuration store).

Expand Down
1 change: 1 addition & 0 deletions _pages/Cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ NOTE: Requires Markdown Extra. See http://michelf.ca/projects/php-markdown/extra
**Framework Guidelines**

* Use C# type aliases instead of the types from the `System` namespace (AV2201)
* Prefer language syntax over explicit calls to underlying implementations (AV2202)
* Build with the highest warning level (AV2210)
* Use Lambda expressions instead of anonymous functions (AV2221)
* Only use the `dynamic` keyword when talking to a dynamic object (AV2230)
Expand Down