Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ public virtual async Task<string> GetFileNameWithNextSerialNumberAsync(string fi
var nextNumber =
fileNames
.Select(x =>
x.Substring(part1.Length, x.LastIndexOf(part2, StringComparison.Ordinal) - part1.Length))
x.LastIndexOf(part2, StringComparison.Ordinal) > 0 ? x.Substring(part1.Length, x.LastIndexOf(part2, StringComparison.Ordinal) - part1.Length) : "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

                    .Where(x => x.EndsWith(part2, StringComparison.Ordinal))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's Ok,but why add new line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to select and parse unused items ("").

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If client upload a file end with ")",also need parse str,so I think both are fine,you decide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep the .Select() line unchanged and add

                    .Where(x => x.EndsWith(part2, StringComparison.Ordinal))

for minimal impact.

.Select(x => int.TryParse(x, out var number) ? number : 0).Where(x => x > 0).OrderBy(x => x)
.TakeWhile((x, i) => x == i + 1).LastOrDefault() + 1;

return $"{part1}{nextNumber}{part2}";
}
}
}
}