Skip to content

Conversation

@mikeebowen
Copy link
Collaborator

@github-actions
Copy link

github-actions bot commented Apr 4, 2025

Test Results

    56 files  + 1      56 suites  +1   54m 22s ⏱️ -10s
 2 053 tests + 3   2 050 ✅ + 3   3 💤 ±0  0 ❌ ±0 
32 049 runs  +73  32 013 ✅ +73  36 💤 ±0  0 ❌ ±0 

Results for commit 01a504f. ± Comparison against base commit 47c920c.

♻️ This comment has been updated with latest results.

}

[Fact]
public void IsValidChild_NullChild_ThrowsArgumentNullException()
Copy link
Member

Choose a reason for hiding this comment

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

should this throw or should it just return false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to return false in latest commit

throw new ArgumentNullException(nameof(element));
}

return Metadata.Children.Elements.Any(el => el.Type.Name.Equals(element.Metadata.Type.Name));
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this only apply on OpenXmlCompositeElement? Should this be virtual and default to false and overriden on that type with this implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's true, updated in latest commit

…CompositeElement, return false instead of throw when element child to test is null
@mikeebowen mikeebowen requested a review from twsouthwick April 25, 2025 18:42
return false;
}

return Metadata.Children.Elements.Any(el => el.Type.Name.Equals(element.Metadata.Type.Name));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
using System.Linq;

if we remove the linq below

twsouthwick
twsouthwick previously approved these changes May 12, 2025
Copy link
Member

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

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

LGTM just a thought about not using LINQ

twsouthwick
twsouthwick previously approved these changes May 13, 2025
Copy link
Member

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

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

LGTM modulo the question

/// </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)
Copy link
Member

Choose a reason for hiding this comment

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

do we need this method on here? Would having it on OpenXmlCompositeElement be enough?

Copy link
Collaborator Author

@mikeebowen mikeebowen May 13, 2025

Choose a reason for hiding this comment

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

I added the virtual method so it would be overridable, but I could make it virtual in OpenXmlCompositeElement

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@twsouthwick see the latest commit

@tomjebo tomjebo merged commit b1d49f3 into dotnet:main Jun 4, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add API to determine if a child is valid for a given element

3 participants