public static UIA.Condition ToNative(ConditionBase condition)
 {
     var propCond = condition as Core.Conditions.PropertyCondition;
     if (propCond != null)
     {
         return new UIA.PropertyCondition(UIA.AutomationProperty.LookupById(propCond.Property.Id), ValueConverter.ToNative(propCond.Value), (UIA.PropertyConditionFlags)propCond.PropertyConditionFlags);
     }
     var boolCond = condition as BoolCondition;
     if (boolCond != null)
     {
         return boolCond.BooleanValue ? UIA.Condition.TrueCondition : UIA.Condition.FalseCondition;
     }
     var notCond = condition as Core.Conditions.NotCondition;
     if (notCond != null)
     {
         return new UIA.NotCondition(ToNative(notCond.Condition));
     }
     var junctCond = condition as JunctionConditionBase;
     if (junctCond != null)
     {
         if (junctCond.ChildCount == 0)
         {
             // No condition in the list, so just create a true condition
             return UIA.Condition.TrueCondition;
         }
         if (junctCond.ChildCount == 1)
         {
             // Only one condition in the list, so just return that one
             return ToNative(junctCond.Conditions[0]);
         }
         if (junctCond is Core.Conditions.AndCondition)
         {
             // Create the and condition
             return new UIA.AndCondition(junctCond.Conditions.Select(ToNative).ToArray());
         }
         // Create the or condition
         return new UIA.OrCondition(junctCond.Conditions.Select(ToNative).ToArray());
     }
     throw new ArgumentException("Unknown condition type");
 }
Example #2
0
 /// <summary>
 /// Converts a FlaUI <see cref="ConditionBase"/> to a native condition.
 /// </summary>
 /// <param name="condition">The condition to convert.</param>
 /// <returns>The native condition.</returns>
 public static UIA.Condition ToNative(ConditionBase condition)
 {
     if (condition is PropertyCondition propCond)
     {
         return(new UIA.PropertyCondition(UIA.AutomationProperty.LookupById(propCond.Property.Id), ValueConverter.ToNative(propCond.Value), (UIA.PropertyConditionFlags)propCond.PropertyConditionFlags));
     }
     if (condition is BoolCondition boolCond)
     {
         return(boolCond.BooleanValue ? UIA.Condition.TrueCondition : UIA.Condition.FalseCondition);
     }
     if (condition is NotCondition notCond)
     {
         return(new UIA.NotCondition(ToNative(notCond.Condition)));
     }
     if (condition is JunctionConditionBase junctionCondition)
     {
         if (junctionCondition.ChildCount == 0)
         {
             // No condition in the list, so just create a true condition
             return(UIA.Condition.TrueCondition);
         }
         if (junctionCondition.ChildCount == 1)
         {
             // Only one condition in the list, so just return that one
             return(ToNative(junctionCondition.Conditions[0]));
         }
         if (junctionCondition is AndCondition)
         {
             // Create the and condition
             return(new UIA.AndCondition(junctionCondition.Conditions.Select(ToNative).ToArray()));
         }
         // Create the or condition
         return(new UIA.OrCondition(junctionCondition.Conditions.Select(ToNative).ToArray()));
     }
     throw new ArgumentException("Unknown condition type");
 }