How to find out an OpenXml element is legit child for another

Ahmet Çiftci 6 Reputation points
2022-03-25T10:07:37.023+00:00

In older versions of OpenXml-sdk, every element has ChildInfoAttributes. So, it was enough to look at the list of ChildInfoAttribute to determine which types of elements it can accept as a child. Recent versions of OpenXml-Sdk removed this.

//Doesn't work in recent versions of OpenXml-Sdk
bool IsLegitChild(Type parent, Type children)
{
    var childInfos =
        (ChildElementInfoAttribute[]) Attribute.GetCustomAttributes(
            parent,
            typeof(ChildElementInfoAttribute));

    return childInfos.Any(x => x.ElementType == children);
}

How to implement this in recent versions of OpenXml-Sdk?

Microsoft 365 and Office | Development | Other
0 comments No comments
{count} vote

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.