-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix type comparison in OrderedItemList #85
Fix type comparison in OrderedItemList #85
Conversation
in the issue i added a comment to look at how the whole class can be cleaned-up. This fix is so "minimal" it seems that request has not been taken into account. Does that mean the class needs no further improvement? |
I beg your pardon. My fault, I concentrated on the description of the issue and did not notice a comment. I will work through it a little bit later. |
… reduce repeatable code.
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.
The class has become a lot clear, so that is great. I have some minor comments on the use of string.format, where i think when we update code we should go for string interpolation.
CDP4Common/Types/OrderedItemList.cs
Outdated
if (index < 0 || index >= this.sortedItems.Count) | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
"index", string.Format("The index {0} does not exist in the ordered item list, valid range is 0 to {1}", index, this.sortedItems.Count - 1)); |
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.
please make use of string interpolation $ syntax instead of string.format
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.
If SortedItems doesn't contain any items, then the error states "valid range is 0 to -1".
CDP4Common/Types/OrderedItemList.cs
Outdated
if (this.sortedItems.Values.Contains(item)) | ||
{ | ||
var thing = item as Thing; | ||
throw new InvalidOperationException(string.Format("The sorted list already contains the item {0}", thing != null ? thing.Iid.ToString() : "An item is not a Thing. Incorrect use of validation.")); |
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.
please make use of string interpolation $ syntax instead of string.format
Since the class is called OrderedItemList I propose that in the exception message we replace sorted with ordered
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.
Only small considerations from my side, so don't let that hold you from merging.
CDP4Common/Types/OrderedItemList.cs
Outdated
if (index < 0 || index >= this.sortedItems.Count) | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
"index", string.Format("The index {0} does not exist in the ordered item list, valid range is 0 to {1}", index, this.sortedItems.Count - 1)); |
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.
If SortedItems doesn't contain any items, then the error states "valid range is 0 to -1".
CDP4Common/Types/OrderedItemList.cs
Outdated
/// <exception cref="ArgumentNullException"> | ||
/// Thrown when <see paramref="value"/> is null. | ||
/// </exception> | ||
private void ValidateValueForNull(object value, string message = "") |
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.
If you make the default value for message "An item cannot be null", you can remove it from 3 other places and it will be easier to reuse it for future changes.
Prerequisites
Description
Closes #82