Skip to content
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

Merged
merged 4 commits into from
Dec 18, 2019

Conversation

IevhenIkonnykov
Copy link
Contributor

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the CDP4-SDK code style guidelines
  • I have provided test coverage for my change (where applicable)

Description

Closes #82

@samatstariongroup
Copy link
Member

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?

@IevhenIkonnykov
Copy link
Contributor Author

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.

Copy link
Member

@samatstariongroup samatstariongroup left a 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.

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));
Copy link
Member

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

Copy link
Contributor

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".

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."));
Copy link
Member

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

Copy link
Contributor

@lxatstariongroup lxatstariongroup left a 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.

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));
Copy link
Contributor

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".

/// <exception cref="ArgumentNullException">
/// Thrown when <see paramref="value"/> is null.
/// </exception>
private void ValidateValueForNull(object value, string message = "")
Copy link
Contributor

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.

@IevhenIkonnykov IevhenIkonnykov merged commit d3ce67a into development Dec 18, 2019
@IevhenIkonnykov IevhenIkonnykov deleted the OrderedItemListTypeComparisonFix branch December 18, 2019 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect type check for Thing in SDK OrderedItemList
4 participants