UIAutomation.ExtensionsMethods.TestControlByPropertiesFromDictionary C# (CSharp) Method

TestControlByPropertiesFromDictionary() static private method

static private TestControlByPropertiesFromDictionary ( this element, object>.Dictionary dict ) : bool
element this
dict object>.Dictionary
return bool
        internal static bool TestControlByPropertiesFromDictionary(
            this IUiElement element,
            Dictionary<string, object> dict)
        {
            bool result = false;
            
            if (null == dict || 0 == dict.Keys.Count()) return result;
            
            foreach (string key in dict.Keys) {

                string keyValue = dict[key].ToString();
                
                const WildcardOptions options = WildcardOptions.IgnoreCase |
                                                WildcardOptions.Compiled;
                
                switch (key) {
                    case "ACCELERATORKEY":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().AcceleratorKey))) {
                                return result;
                        }
                        break;
                    case "ACCESSKEY":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().AccessKey))) {
                                return result;
                        }
                        break;
                    case "AUTOMATIONID":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().AutomationId))) {
                                return result;
                        }
                        break;
                    case "CLASS":
                    case "CLASSNAME":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().ClassName))) {
                                return result;
                        }
                        break;
                    case "CONTROLTYPE":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().ControlType.ProgrammaticName.Substring(12)))) {
                                return result;
                        }
                        break;
                    case "FRAMEWORKID":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().FrameworkId))) {
                                return result;
                        }
                        break;
                    case "HASKEYBOARDFOCUS":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().HasKeyboardFocus.ToString()))) {
                                return result;
                        }
                        break;
                    case "HELPTEXT":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().HelpText))) {
                                return result;
                        }
                        break;
                    case "ISCONTENTELEMENT":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().IsContentElement.ToString()))) {
                                return result;
                        }
                        break;
                    case "ISCONTROLELEMENT":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().IsControlElement.ToString()))) {
                                return result;
                        }
                        break;
                    case "ISENABLED":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().IsEnabled.ToString()))) {
                                return result;
                        }
                        break;
                    case "ISKEYBOARDFOCUSABLE":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().IsKeyboardFocusable.ToString()))) {
                                return result;
                        }
                        break;
                    case "ISOFFSCREEN":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().IsOffscreen.ToString()))) {
                                return result;
                        }
                        break;
                    case "ISPASSWORD":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().IsPassword.ToString()))) {
                                return result;
                        }
                        break;
                    case "ISREQUIREDFORFORM":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().IsRequiredForForm.ToString()))) {
                                return result;
                        }
                        break;
                    case "ITEMSTATUS":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().ItemStatus))) {
                                return result;
                        }
                        break;
                    case "ITEMTYPE":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().ItemType))) {
                                return result;
                        }
                        break;
                    case "LABELEDBY":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().LabeledBy.Current.Name))) {
                                return result;
                        }
                        break;
                    case "LOCALIZEDCONTROLTYPE":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().LocalizedControlType))) {
                                return result;
                        }
                        break;
                    case "NAME":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().Name))) {
                                return result;
                        }
                        break;
                    case "NATIVEWINDOWHANDLE":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().NativeWindowHandle.ToString()))) {
                                return result;
                        }
                        break;
                    case "ORIENTATION":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().Orientation.ToString()))) {
                                return result;
                        }
                        break;
                    case "PROCESSID":
                        if ( !(new WildcardPattern(
                            keyValue,
                            options).IsMatch(element.GetCurrent().ProcessId.ToString()))) {
                                return result;
                        }
                        break;
                    default:
                        (new CommonCmdletBase()).WriteError(
                            // this,
                            new CommonCmdletBase(),
                            "Wrong AutomationElement parameter is provided: " + key,
                            "WrongParameter",
                            ErrorCategory.InvalidArgument,
                            true);
                        break;
                }
            }
            
            result = true;
            return result;
        }