title: Getting actual InvokePattern object from a list of AutomationPattern objects
body: <p>I have a list of <code>AutomationPattern</code> objects retrieved from the <code>AutomationElement.GetSupportedPatterns()</code> method. And now I need to know what kind of patterns are there, I mean is the single item <code>InvokePattern</code> or <code>ExpandCollapsePattern</code>. To be more specific let's assume we have an <code>AutomationPattern</code> object and we know that the <code>ProgrammaticName</code> property of this object is the "InvokePatternIdentifiers.Pattern" string, can I somehow get object of type <code>InvokePattern</code>?</p>
  
  <p>I have implemented my own way of solving this problem using <code>AutomationPattern.ProgrammaticName</code> property and a big switch statement, is there another way to do this?</p>
  
  <p>Here is my implemetation:</p>
  
  <pre><code>    public object GetActualAutomationPattern(AutomationElement element, AutomationPattern pattern)
      {
          switch (pattern.ProgrammaticName)
          {
              case "DockPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(DockPattern.Pattern) as DockPattern;
              case "ExpandCollapsePatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
              case "GridPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(GridPattern.Pattern) as GridPattern;
              case "GridItemPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(GridItemPattern.Pattern) as GridItemPattern;
              case "InvokePatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
              case "MultipleViewPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(MultipleViewPattern.Pattern) as MultipleViewPattern;
              case "RangeValuePatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern;
              case "ScrollPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern;
              case "ScrollItemPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(ScrollItemPattern.Pattern) as ScrollItemPattern;
              case "SelectionPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
              case "SelectionItemPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
              case "TablePatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(TablePattern.Pattern) as TablePattern;
              case "TableItemPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(TableItemPattern.Pattern) as TableItemPattern;
              case "TogglePatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
              case "TransformPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;
              case "ValuePatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
              case "WindowPatternIdentifiers.Pattern":
                  return element.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
              default:
                  return pattern;
          }
      }
  </code></pre>