Automation.UI.Util.AutomationPropertyHelper.Equals C# (CSharp) Method

Equals() public static method

Compares the specified property values to see if they are equal.
public static Equals ( object property1, object property2 ) : bool
property1 object The first property.
property2 object The second property.
return bool
        public static new bool Equals(object property1, object property2)
        {
            // If the type of the property is ControlType, compare the ids instead.
            var type1 = property1.GetType();
            if (type1 == typeof(ControlType)) property1 = ((ControlType) property1).Id;
            // If the type of the property is ControlType, compare the ids instead.
            var type2 = property2.GetType();
            if (type2 == typeof(ControlType)) property2 = ((ControlType) property2).Id;
            // Compare and return.
            return property1.Equals(property2);
        }

Usage Example

        /// <summary>
        ///     Check to see if the specified automation element meets the requirements of the specified condition.
        /// </summary>
        /// <param name="condition">The condition to check.</param>
        /// <param name="element">The automation element to check.</param>
        /// <returns>True if the automation element meets the condition's requirements. False otherwise.</returns>
        public static bool IsMeetsRequirements(Condition condition, AutomationElement element)
        {
            var type = condition.GetType();

            if (condition == Condition.TrueCondition)
            {
                // Always return true.
                return(true);
            }
            if (condition == Condition.FalseCondition)
            {
                // Always returns false.
                return(false);
            }
            if (type == typeof(NotCondition))
            {
                // Return the negation of the inner condition.
                return(!IsMeetsRequirements(((NotCondition)condition).Condition, element));
            }
            if (type == typeof(OrCondition))
            {
                // Return true if any of the inner conditions are true.
                return(((OrCondition)condition).GetConditions().Any(inner => IsMeetsRequirements(inner, element)));
            }
            if (type == typeof(AndCondition))
            {
                // Return true if all of the inner conditions are true.
                return(((AndCondition)condition).GetConditions().All(inner => IsMeetsRequirements(inner, element)));
            }
            if (type == typeof(StringPropertyCondition))
            {
                // Return true if the string property condition matches.
                return(((StringPropertyCondition)condition).IsMatch(element));
            }
            if (type == typeof(PropertyCondition))
            {
                // Return true if the property condition matches.
                var propertyCondition = (PropertyCondition)condition;
                var actual            = element.GetCurrentPropertyValue(propertyCondition.Property);
                var expected          = propertyCondition.Value;

                Trace.WriteLine("Checking '" + AutomationPropertyHelper.ToString(actual) + "'='" + AutomationPropertyHelper.ToString(expected) + "'", "UIAutomation-ConditionHelper");
                return(AutomationPropertyHelper.Equals(actual, expected));
            }
            // Don't know how to match any other conditions.
            throw new NotSupportedException("Condition '" + type + "' is not supported");
        }