Skip to content

Commit 9b0b78a

Browse files
authored
Abstract check for file formats including all known versions (#348)
1 parent 8c7c199 commit 9b0b78a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

DocumentFormat.OpenXml/OfficeVersions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ public static bool Any(this FileFormatVersions version)
2020
|| version == FileFormatVersions.Office2013;
2121
}
2222

23+
/// <summary>
24+
/// Determines if the supplied version is valid for all versions
25+
/// </summary>
26+
/// <param name="version">The version to check</param>
27+
/// <returns>True if the version is all of the known versions, otherwise false</returns>
28+
public static bool All(this FileFormatVersions version)
29+
{
30+
var all = FileFormatVersions.Office2007
31+
| FileFormatVersions.Office2010
32+
| FileFormatVersions.Office2013;
33+
34+
return version == all;
35+
}
36+
2337
/// <summary>
2438
/// Combines values for the given version and all versions that come after it
2539
/// </summary>

DocumentFormat.OpenXml/src/Framework/AlternateContent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ internal bool IsProcessContent(OpenXmlElement element)
799799

800800
internal AttributeAction GetAttributeAction(string ns, string localName, FileFormatVersions format)
801801
{
802-
if (format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007) || format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007 | FileFormatVersions.Office2013))
802+
if (format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007) || format.All())
803803
{
804804
return AttributeAction.Normal;
805805
}
@@ -829,7 +829,7 @@ internal AttributeAction GetAttributeAction(string ns, string localName, FileFor
829829

830830
internal ElementAction GetElementAction(OpenXmlElement element, FileFormatVersions format)
831831
{
832-
if (format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007) || format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007 | FileFormatVersions.Office2013))
832+
if (format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007) || format.All())
833833
{
834834
return ElementAction.Normal;
835835
}

0 commit comments

Comments
 (0)