'How can you get supported Patterns of an IUIAutomationElement

I am regularly using the IUIAutomation wrapper nuget packages in my dotnet core project. Lately I have been trying to figure out how someone could get information about supported Patterns of a particular Element. I know that elements with fluctuating Pattern assignments exist and would like to improve the stability of my automation.

A good example is a button that sometimes has the control pattern Invoke assigned and sometimes the control pattern is ExpandCollapse



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source