-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
12 additions
and
11 deletions.
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
# MA0016 - Prefer returning collection abstraction instead of implementation | ||
# MA0016 - Prefer using collection abstraction instead of implementation | ||
|
||
Methods and properties visible to other assemblies (`public` or `protected`) should use collection interfaces instead of collection implementations. | ||
|
||
````c# | ||
public List<string> Prop { get; set; } // report diagnostic | ||
public List<string> Prop { get; set; } // non-compliant | ||
public IList<string> Prop { get; set; } // ok | ||
public void Method(Dictionary<string, string> arg) {} // non-compliant | ||
```` | ||
|
||
The analyzer detects `List<T>`, `HashSet<T>`, `Dictionary<TKey,TValue>`, and `System.Collections.ObjectModel.Collection<T>`. The rules is disabled if the property is decorated with an XML serialization attribute. |
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
df15420
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @meziantou ,
regarding MA0016
if
The rules is disabled if the property is decorated with an XML serialization attribute
Shouldn't this (disabling) also apply if the class is decorated with SerializableAttribute ?
df15420
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is already the case. Here's the code to detect if a property is decorated:
Meziantou.Analyzer/src/Meziantou.Analyzer/Rules/PreferReturningCollectionAbstractionInsteadOfImplementationAnalyzer.cs
Lines 99 to 103 in aa5f193
df15420
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, this is not the case. Since we agree, I have sent a pull request as offer.