Skip to content

Commit 8ac9d24

Browse files
committed
Ensured ArgumentException included nameof(parameter)
Not all cases where an `ArgumentException` can be thrown include the parameter name. In these cases, the general preference is to use `nameof(parameter)` so that the name is validated against the actual parameter name, and mismatches will be detected if the parameter name changes.
1 parent 7e6cb4c commit 8ac9d24

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

OnTopic/Collections/AttributeValueCollection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ protected override void InsertItem(int index, AttributeValue item) {
554554
throw new ArgumentException(
555555
$"An {nameof(AttributeValue)} with the Key '{item.Key}' already exists. The Value of the existing item is " +
556556
$"{this[item.Key].Value}; the new item's Value is '{item.Value}'. These {nameof(AttributeValue)}s are associated " +
557-
$"with the {nameof(Topic)} '{_associatedTopic.GetUniqueKey()}'."
557+
$"with the {nameof(Topic)} '{_associatedTopic.GetUniqueKey()}'.",
558+
nameof(item)
558559
);
559560
}
560561
}

OnTopic/Internal/Reflection/TypeMemberInfoCollection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ protected override void InsertItem(int index, MemberInfoCollection item) {
488488
else {
489489
throw new ArgumentException(
490490
$"The '{nameof(TypeMemberInfoCollection)}' already contains the {nameof(MemberInfoCollection)} of the Type " +
491-
$"'{item.Type}'.");
491+
$"'{item.Type}'.",
492+
nameof(item)
493+
);
492494
}
493495
}
494496

OnTopic/Repositories/TopicRepositoryBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ public virtual int Save([ValidatedNotNull]Topic topic, bool isRecursive = false)
315315
if (contentTypeDescriptor is null) {
316316
throw new ArgumentException(
317317
$"The Content Type \"{topic.ContentType}\" referenced by \"{topic.Key}\" could not be found under " +
318-
$"\"Configuration:ContentTypes\". There are currently {contentTypeDescriptors.Count} ContentTypes in the Repository."
318+
$"\"Configuration:ContentTypes\". There are currently {contentTypeDescriptors.Count} ContentTypes in the Repository.",
319+
nameof(topic)
319320
);
320321
}
321322

0 commit comments

Comments
 (0)