Skip to content

Commit 86fd5c4

Browse files
committed
Migrated view model List<> properties to use Collection<>
Microsoft's design guidelines recommend that public interfaces use `Collection<T>` instead of `List<T>` (CA1002). The `List<T>` type is faster, and optimized for performance, but includes a lot of low-level members that most users don't need, while `Collection<T>` has more high-level convenience members that are more intuitive for most users. As this was a breaking change, however, we didn't implement this as part of our implementation of Microsoft's updated Code Analysis (27e6940). Now that we're preparing for a major release, we're able to make these changes which could potentially break some implementations. Notably, this will break implementations that specifically access the member as a `List<T>` (e.g., as a cast or assignment), or which call some of the `List<T>` specific methods, such as `AddRange()`. These calls were previously removed from elsewhere in the OnTopic library in preparation for this migration, but may still persist in some client implementations.
1 parent 704c8de commit 86fd5c4

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

OnTopic.Tests/ViewModels/CompatiblePropertyTopicViewModel.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| Project Topics Library
55
\=============================================================================================================================*/
66
using System;
7-
using System.Collections.Generic;
7+
using System.Collections.ObjectModel;
88
using System.Diagnostics.CodeAnalysis;
99
using OnTopic.Metadata;
1010

@@ -25,9 +25,7 @@ public class CompatiblePropertyTopicViewModel {
2525

2626
public ModelType ModelType { get; set; }
2727

28-
#pragma warning disable CA1002 // Do not expose generic lists
29-
public List<DateTime>? VersionHistory { get; set; }
30-
#pragma warning restore CA1002 // Do not expose generic lists
28+
public Collection<DateTime>? VersionHistory { get; set; }
3129

3230
} //Class
3331
} //Namespace

OnTopic/GlobalSuppressions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77

88
[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "StringComparison overload not supported by .NET Standard 2.0", Scope = "member", Target = "~M:OnTopic.Topic.GetWebPath~System.String")]
99
[assembly: SuppressMessage("Usage", "CA2249:Consider using 'string.Contains' instead of 'string.IndexOf'", Justification = "StringComparison overload not supported by .NET Standard 2.0.", Scope = "member", Target = "~M:OnTopic.Querying.TopicExtensions.FindAllByAttribute(OnTopic.Topic,System.String,System.String)~OnTopic.Collections.ReadOnlyTopicCollection{OnTopic.Topic}")]
10-
[assembly: SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "Expected by convention for OnTopic Editor", Scope = "namespaceanddescendants", Target = "~N:OnTopic")]
11-
[assembly: SuppressMessage("Design", "CA1002:Do not expose generic lists", Justification = "Breaking change; deferred to major version.", Scope = "namespaceanddescendants", Target = "~N:OnTopic")]
10+
[assembly: SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "Expected by convention for OnTopic Editor", Scope = "namespaceanddescendants", Target = "~N:OnTopic")]

OnTopic/Internal/Reflection/TypeMemberInfoCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ private static bool IsSettableType(Type sourceType, Type? targetType = null) {
454454
/// <summary>
455455
/// A list of types that are allowed to be set using <see cref="SetPropertyValue(Object, String, String)"/>.
456456
/// </summary>
457-
public static List<Type> SettableTypes { get; }
457+
public static Collection<Type> SettableTypes { get; }
458458

459459
/*==========================================================================================================================
460460
| OVERRIDE: INSERT ITEM

OnTopic/Topic.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
\=============================================================================================================================*/
66
using System;
77
using System.Collections.Generic;
8+
using System.Collections.ObjectModel;
89
using System.Diagnostics.CodeAnalysis;
910
using System.Globalization;
1011
using System.Linq;
@@ -644,7 +645,7 @@ public Topic? DerivedTopic {
644645
/// its derived providers).
645646
/// </remarks>
646647
/// <value>The current <see cref="Topic"/>'s version history.</value>
647-
public List<DateTime> VersionHistory { get; }
648+
public Collection<DateTime> VersionHistory { get; }
648649

649650
#endregion
650651

0 commit comments

Comments
 (0)