Skip to content

Commit 923a052

Browse files
committed
per feedback
1 parent fb9ea52 commit 923a052

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/DocumentFormat.OpenXml.Framework/EnumerableExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal static class EnumerableExtensions
1212
/// <summary>
1313
/// Similar to <see cref="Enumerable.FirstOrDefault{TSource}(IEnumerable{TSource})"/> but will also verify that at most there is one.
1414
/// </summary>
15-
public static T? FirstOrDefaultAndMaxOne<T>(this IEnumerable<T> enumerable, Func<Exception>? exThrow = null)
15+
public static T? FirstOrDefaultAndMaxOne<T>(this IEnumerable<T> enumerable, Func<Exception>? exceptionFactory = null)
1616
{
1717
using var e = enumerable.GetEnumerator();
1818

@@ -22,7 +22,7 @@ internal static class EnumerableExtensions
2222

2323
if (e.MoveNext())
2424
{
25-
throw exThrow?.Invoke() ?? throw new InvalidOperationException("Max of a single item should be in the enumerable");
25+
throw exceptionFactory?.Invoke() ?? throw new InvalidOperationException(ExceptionMessages.FirstOrDefaultMaxOne);
2626
}
2727

2828
return first;

src/DocumentFormat.OpenXml.Framework/Resources/ExceptionMessages.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DocumentFormat.OpenXml.Framework/Resources/ExceptionMessages.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,7 @@
411411
<data name="FailedToOpenPackage" xml:space="preserve">
412412
<value>Package could not be opened for stream. See inner exception for details and be aware that there are behavior differences in stream support between .NET Framework and Core.</value>
413413
</data>
414+
<data name="FirstOrDefaultMaxOne" xml:space="preserve">
415+
<value>The enumerable contained more than a single element when only zero or one are allowed.</value>
416+
</data>
414417
</root>

0 commit comments

Comments
 (0)