-
Notifications
You must be signed in to change notification settings - Fork 573
Add OpenXmlElement.IsValidChild method #1915
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
Changes from 8 commits
caa1110
738b2f2
c53a74a
f802e2a
ecacca6
451523e
4d37e79
a24c6b0
e688eed
c924f3c
c08a012
01a504f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||||||||
| using System.Diagnostics.CodeAnalysis; | ||||||||||||
| using System.Globalization; | ||||||||||||
| using System.IO; | ||||||||||||
| using System.Linq; | ||||||||||||
| using System.Text; | ||||||||||||
| using System.Xml; | ||||||||||||
|
|
||||||||||||
|
|
@@ -534,6 +535,21 @@ public override void RemoveAllChildren() | |||||||||||
|
|
||||||||||||
| #endregion | ||||||||||||
|
|
||||||||||||
| /// <summary> | ||||||||||||
| /// Determines if the specified element is a valid child of the current element. | ||||||||||||
| /// </summary> | ||||||||||||
| /// <param name="element">The element to check.</param> | ||||||||||||
| /// <returns>True if the specified element is a valid child; otherwise, false.</returns> | ||||||||||||
| public override bool IsValidChild(OpenXmlElement element) | ||||||||||||
| { | ||||||||||||
| if (element is null) | ||||||||||||
| { | ||||||||||||
| return false; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return Metadata.Children.Elements.Any(el => el.Type.Name.Equals(element.Metadata.Type.Name)); | ||||||||||||
|
||||||||||||
| return Metadata.Children.Elements.Any(el => el.Type.Name.Equals(element.Metadata.Type.Name)); | |
| foreach(var child in Metadata.Children.Elements) | |
| { | |
| child.Type.Name.Equals(element.Metadata.Type.Name); | |
| } |
LINQ adds some allocations that we don't really need
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1330,6 +1330,16 @@ public bool IsBefore(OpenXmlElement element) | |
| return GetOrder(this, element) == ElementOrder.Before; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines if the specified element is a valid child of the current element. | ||
| /// </summary> | ||
| /// <param name="element">The element to check.</param> | ||
| /// <returns>True if the specified element is a valid child; otherwise, false.</returns> | ||
| public virtual bool IsValidChild(OpenXmlElement element) | ||
|
||
| { | ||
| return false; | ||
| } | ||
|
|
||
| private enum ElementOrder | ||
| { | ||
| Same, // same element | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we remove the linq below