Skip to content

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

@cwensley

Description

@cwensley

When trying to modify a document, one needs to know if a particular element can add a particular child before doing so. Before, this was one way of doing so which is no longer works:

public static bool CanAddChild<T>(this OpenXmlElement element)
{
	if (element == null)
		return false;
	var attributes = element.GetType().GetCustomAttributes<ChildElementInfoAttribute>();
	return attributes.Any(r => r.ElementType == typeof(T));
}

There does not appear to be a way to do this anymore as all of the metadata information is internal and created in the internal ConfigureMetadata override.

Describe the solution you'd like
An API such as the above to determine and/or list the valid children of a given element.

Describe alternatives you've considered
One way might be to add the child then validate it, but this seems the wrong approach.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions