Skip to content

Commit 5eff966

Browse files
authored
Use SingleOrDefault instead of custom FirstOrDefaultAndMaxOne (#1899)
1 parent 4c76465 commit 5eff966

5 files changed

Lines changed: 5 additions & 49 deletions

File tree

src/DocumentFormat.OpenXml.Framework/EnumerableExtensions.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

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

Lines changed: 0 additions & 9 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: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120-
<data name="AddedPartIsNotAllowed" xml:space="preserve">
121-
<value>The part cannot be added here.</value>
122-
</data>
123120
<data name="CannotChangeDocumentType" xml:space="preserve">
124121
<value>Cannot change the document type.</value>
125122
</data>
@@ -411,8 +408,8 @@
411408
<data name="FailedToOpenPackage" xml:space="preserve">
412409
<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>
413410
</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>
411+
<data name="AddedPartIsNotAllowed" xml:space="preserve">
412+
<value>The part cannot be added here.</value>
416413
</data>
417414
<data name="EncryptedPackageNotSupported" xml:space="preserve">
418415
<value>Encrypted packages are not supported.</value>

src/DocumentFormat.OpenXml.Framework/Validation/Semantic/RelationshipTypeConstraint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public RelationshipTypeConstraint(OpenXmlQualifiedName attribute, string type)
6464
{
6565
var pair = current.Part.Parts
6666
.Where(p => p.RelationshipId == attribute.Value.InnerText)
67-
.FirstOrDefaultAndMaxOne();
67+
.SingleOrDefault();
6868

6969
if (pair is { })
7070
{

src/DocumentFormat.OpenXml.Framework/Validation/Semantic/SemanticConstraint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ protected static bool GetAttrNumVal(OpenXmlSimpleType attributeValue, out double
241241
CultureInfo.InvariantCulture, out value);
242242
}
243243

244+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1851:Possible multiple enumerations of 'IEnumerable' collection", Justification = "We're resetting the parts variable, but the analyzer doesn't realize that")]
244245
private static OpenXmlPart? GetPartThroughPartPath(IEnumerable<IdPartPair> pairs, string[] path)
245246
{
246247
var foundPart = default(OpenXmlPart);
@@ -251,7 +252,7 @@ protected static bool GetAttrNumVal(OpenXmlSimpleType attributeValue, out double
251252
foundPart = parts
252253
.Where(p => p.OpenXmlPart.GetType().Name == path[i])
253254
.Select(t => t.OpenXmlPart)
254-
.FirstOrDefaultAndMaxOne(static () => new System.IO.FileFormatException(ValidationResources.MoreThanOnePartForOneUri));
255+
.SingleOrDefault();
255256

256257
if (foundPart is not { })
257258
{

0 commit comments

Comments
 (0)