-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #368 from green-code-initiative/vlj/GCI90
- Loading branch information
Showing
5 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"title": "Use Cast instead of Select to cast", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
"eco-design", | ||
"creedengo", | ||
"performance", | ||
"bad-practice" | ||
], | ||
"defaultSeverity": "Major" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
:!sectids: | ||
|
||
Use Cast instead of Select to cast. | ||
|
||
== Why is this an issue ? | ||
|
||
Cast is more efficient than Select for casting operations, its usage leads to better performance. | ||
|
||
=== When can it be ignored ? | ||
|
||
This rule shouldn't be ignored. | ||
|
||
== Non compliant example | ||
|
||
[source, cs] | ||
---- | ||
void Test(IEnumerable<string> items) | ||
{ | ||
var asObjects = items.Select(x => (object)x); | ||
} | ||
---- | ||
|
||
== Compliant example | ||
|
||
[source, cs] | ||
---- | ||
void Test(IEnumerable<string> items) | ||
{ | ||
var asObjects = items.Cast<object>(); | ||
} | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
"bad-practice" | ||
], | ||
"defaultSeverity": "Major" | ||
} | ||
} |