Skip to content

Commit 427959b

Browse files
committed
Migrated [Obsolete()] statements to use nameof() for members
With C# 10, we can now use string interpolation with attributes, so long as the values are constants. This allows us to use `nameof()` for references to classes and class members.
1 parent 5852d10 commit 427959b

34 files changed

Lines changed: 91 additions & 52 deletions

OnTopic.AspNetCore.Mvc/Models/NavigationViewModel{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class NavigationViewModel<T> where T : class, IHierarchicalTopicViewModel
7777
/// </summary>
7878
/// <inheritdoc cref="CurrentWebPath"/>
7979
[ExcludeFromCodeCoverage]
80-
[Obsolete("The CurrentKey property has been replaced in favor of CurrentWebPath.", true)]
80+
[Obsolete($"The {nameof(CurrentKey)} property has been replaced in favor of {nameof(CurrentWebPath)}.", true)]
8181
public string CurrentKey { get; set; } = default!;
8282

8383
} //Class

OnTopic.TestDoubles/StubTopicRepository.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ public IEnumerable<AttributeRecord> GetAttributesProxy(
205205
\-------------------------------------------------------------------------------------------------------------------------*/
206206
/// <inheritdoc cref="TopicRepository.GetContentTypeDescriptors(ContentTypeDescriptor)" />
207207
[ExcludeFromCodeCoverage]
208-
[Obsolete("Deprecated. Instead, use the new SetContentTypeDescriptorsProxy(), which provides the same function.", true)]
208+
[Obsolete(
209+
$"Deprecated. Instead, use the new {nameof(SetContentTypeDescriptorsProxy)}, which provides the same function.",
210+
true
211+
)]
209212
public ContentTypeDescriptorCollection GetContentTypeDescriptorsProxy(ContentTypeDescriptor topicGraph) =>
210213
base.SetContentTypeDescriptors(topicGraph);
211214

OnTopic.ViewModels/TopicViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public record TopicViewModel: ITopicViewModel, ICoreTopicViewModel, IAssociatedT
7676
\-------------------------------------------------------------------------------------------------------------------------*/
7777
/// <inheritdoc/>
7878
[ExcludeFromCodeCoverage]
79-
[Obsolete("The IsHidden property is no longer supported by TopicViewModel.", true)]
79+
[Obsolete($"The {nameof(IsHidden)} property is no longer supported by {nameof(TopicViewModel)}.", true)]
8080
[DisableMapping]
8181
public bool IsHidden { get; init; }
8282

OnTopic.ViewModels/TopicViewModelLookupService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ public TopicViewModelLookupService(IEnumerable<Type>? types = null) : base(types
5858
>-------------------------------------------------------------------------------------------------------------------------
5959
| These will be removed in the next major version of OnTopic.
6060
\-----------------------------------------------------------------------------------------------------------------------*/
61-
#pragma warning disable CS0618 // Type or member is obsolete
6261
TryAdd(typeof(ListTopicViewModel));
63-
#pragma warning restore CS0618 // Type or member is obsolete
6462

6563
/*------------------------------------------------------------------------------------------------------------------------
6664
| Add support types

OnTopic.ViewModels/_items/ListTopicViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
\=============================================================================================================================*/
66
using System;
77
using System.Collections;
8+
using OnTopic.Mapping.Annotations;
89

910
namespace OnTopic.ViewModels {
1011

@@ -28,8 +29,8 @@ namespace OnTopic.ViewModels {
2829
/// </para>
2930
/// </remarks>
3031
[Obsolete(
31-
"There should not be a need for a LookupListItem view model. If these must be referenced, prefer using e.g. [MapAs()] " +
32-
"to specify a common view model.",
32+
$"There should not be a need for a LookupListItem view model. If these must be referenced, prefer using e.g. " +
33+
$"{nameof(MapAsAttribute)} to specify a common view model.",
3334
false
3435
)]
3536
public record ListTopicViewModel: ContentItemTopicViewModel {

OnTopic/Associations/TopicRelationshipMultiMap.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void Clear(string relationshipKey) {
7777

7878
/// <inheritdoc cref="Clear(String)"/>
7979
[ExcludeFromCodeCoverage]
80-
[Obsolete("The ClearTopics(relationshipKey) method has been renamed to Clear(relationshipKey).", true)]
80+
[Obsolete($"The {nameof(ClearTopics)} method has been renamed to {nameof(Clear)}.", true)]
8181
public void ClearTopics(string relationshipKey) => Clear(relationshipKey);
8282

8383
/*==========================================================================================================================
@@ -149,12 +149,12 @@ internal bool Remove(string relationshipKey, Topic topic, bool isIncoming) {
149149

150150
/// <inheritdoc cref="Remove(String, Topic)"/>
151151
[ExcludeFromCodeCoverage]
152-
[Obsolete("The RemoveTopic() method has been renamed to Remove().", true)]
152+
[Obsolete($"The {nameof(RemoveTopic)} method has been renamed to {nameof(Remove)}.", true)]
153153
public bool RemoveTopic(string relationshipKey, Topic topic) => Remove(relationshipKey, topic);
154154

155155
/// <inheritdoc cref="Remove(String, Topic, Boolean)"/>
156156
[ExcludeFromCodeCoverage]
157-
[Obsolete("The RemoveTopic() method has been renamed to Remove().", true)]
157+
[Obsolete($"The {nameof(RemoveTopic)} method has been renamed to {nameof(Remove)}.", true)]
158158
public bool RemoveTopic(string relationshipKey, Topic topic, bool isIncoming) =>
159159
Remove(relationshipKey, topic, isIncoming);
160160

@@ -232,12 +232,12 @@ internal void SetValue(string relationshipKey, Topic topic, bool? markDirty, boo
232232

233233
/// <inheritdoc cref="SetValue(String, Topic, Boolean?)"/>
234234
[ExcludeFromCodeCoverage]
235-
[Obsolete("The SetTopic() method has been renamed to SetValue().", true)]
235+
[Obsolete($"The {nameof(SetTopic)} method has been renamed to {nameof(SetValue)}.", true)]
236236
public void SetTopic(string relationshipKey, Topic topic, bool? isDirty = null) => SetValue(relationshipKey, topic, isDirty);
237237

238238
/// <inheritdoc cref="SetValue(String, Topic, Boolean?, Boolean)"/>
239239
[ExcludeFromCodeCoverage]
240-
[Obsolete("The SetTopic() method has been renamed to SetValue().", true)]
240+
[Obsolete($"The {nameof(SetTopic)} method has been renamed to {nameof(SetValue)}.", true)]
241241
public void SetTopic(string relationshipKey, Topic topic, bool? isDirty, bool isIncoming) =>
242242
SetValue(relationshipKey, topic, isDirty, isIncoming);
243243

OnTopic/Collections/KeyedTopicCollection{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public KeyedTopicCollection(IEnumerable<T>? topics = null) : base(StringComparer
5050

5151
/// <inheritdoc cref="GetValue(String)"/>
5252
[ExcludeFromCodeCoverage]
53-
[Obsolete("The GetTopic() method has been renamed to GetValue().", true)]
53+
[Obsolete($"The {nameof(GetTopic)} method has been renamed to {nameof(GetValue)}.", true)]
5454
public T? GetTopic(string key) => GetValue(key);
5555

5656
/*==========================================================================================================================

OnTopic/Collections/ReadOnlyKeyedTopicCollection{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class ReadOnlyKeyedTopicCollection<T> : ReadOnlyCollection<T> where T : T
6565

6666
/// <inheritdoc cref="GetValue(String)"/>
6767
[ExcludeFromCodeCoverage]
68-
[Obsolete("The GetTopic() method has been renamed to GetValue().", true)]
68+
[Obsolete($"The {nameof(GetTopic)} method has been renamed to {nameof(GetValue)}.", true)]
6969
public T? GetTopic(string key) => GetValue(key);
7070

7171
/*==========================================================================================================================

OnTopic/Collections/ReadOnlyTopicCollection.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public class ReadOnlyTopicCollection : ReadOnlyCollection<Topic> {
4949
/// <inheritdoc cref="ReadOnlyKeyedTopicCollection{T}.GetTopic(String)"/>
5050
[ExcludeFromCodeCoverage]
5151
[Obsolete(
52-
"The GetTopic() method is not implemented on ReadOnlyTopicCollection. Use ReadOnlyKeyedTopicCollection instead.",
52+
$"The {nameof(GetValue)} method is not implemented on {nameof(ReadOnlyTopicCollection)}. Use " +
53+
$"{nameof(ReadOnlyKeyedTopicCollection)} instead.",
5354
true
5455
)]
5556
public Topic? GetValue(string key) => throw new NotImplementedException();
@@ -60,7 +61,8 @@ public class ReadOnlyTopicCollection : ReadOnlyCollection<Topic> {
6061
/// <inheritdoc cref="ReadOnlyKeyedTopicCollection{T}"/>
6162
[ExcludeFromCodeCoverage]
6263
[Obsolete(
63-
"Indexing by key is not implemented on ReadOnlyTopicCollection. Use ReadOnlyKeyedTopicCollection instead.",
64+
$"Indexing by key is not implemented on {nameof(ReadOnlyTopicCollection)}. Use {nameof(ReadOnlyKeyedTopicCollection)} " +
65+
$"instead.",
6466
true
6567
)]
6668
public Topic this[string key] => throw new ArgumentOutOfRangeException(nameof(key));

OnTopic/Collections/Specialized/ReadOnlyTopicMultiMap.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public ReadOnlyTopicCollection GetValues(string key) {
111111

112112
/// <inheritdoc cref="GetValues(String)"/>
113113
[ExcludeFromCodeCoverage]
114-
[Obsolete("The GetTopics() method has been renamed to GetValues().", true)]
114+
[Obsolete($"The {nameof(GetTopics)} method has been renamed to {nameof(GetValues)}.", true)]
115115
public ReadOnlyTopicCollection GetTopics(string key) => GetValues(key);
116116

117117
/*==========================================================================================================================
@@ -138,12 +138,12 @@ public ReadOnlyTopicCollection GetAllValues(string contentType) =>
138138

139139
/// <inheritdoc cref="GetAllValues(String)"/>
140140
[ExcludeFromCodeCoverage]
141-
[Obsolete("The GetAllTopics() method has been renamed to GetAllValues().", true)]
141+
[Obsolete($"The {nameof(GetAllTopics)} method has been renamed to {nameof(GetAllValues)}.", true)]
142142
public ReadOnlyTopicCollection GetAllTopics(string key) => GetAllValues(key);
143143

144144
/// <inheritdoc cref="GetAllValues(String)"/>
145145
[ExcludeFromCodeCoverage]
146-
[Obsolete("The GetAllTopics() method has been renamed to GetAllValues().", true)]
146+
[Obsolete($"The {nameof(GetAllTopics)} method has been renamed to {nameof(GetAllValues)}.", true)]
147147
public ReadOnlyTopicCollection GetAllTopics() => GetAllValues();
148148

149149
/*==========================================================================================================================

0 commit comments

Comments
 (0)