public bool TryGetPropertyValue <T>(PropertyId property, out T value)
        {
            if (Equals(property, PropertyId.NotSupportedByFramework))
            {
                throw new NotSupportedByFrameworkException();
            }

            var isCacheActive = CacheRequest.IsCachingActive;

            try
            {
                var internalValue = this.InternalGetPropertyValue(property.Id, isCacheActive, useDefaultIfNotSupported: false);
                if (internalValue == this.Automation.NotSupportedValue)
                {
                    value = default(T);
                    return(false);
                }

                value = property.Convert <T>(this.Automation, internalValue);
                return(true);
            }
            catch (Exception ex)
            {
                if (isCacheActive)
                {
                    var cacheRequest = CacheRequest.Current;
                    if (!cacheRequest.Properties.Contains(property))
                    {
                        throw new PropertyNotCachedException(property, ex);
                    }
                }

                // Should actually never come here
                throw;
            }
        }
 public void Add(PropertyId property)
 {
     this.Properties.Add(property);
 }
 public PropertyNotSupportedException(string message, PropertyId property, Exception innerException)
     : base(message, innerException)
 {
     this.Property = property;
 }
 public PropertyNotSupportedException(PropertyId property, Exception innerException)
     : base(string.Format(DefaultMessageWithData, property.Name), innerException)
 {
     this.Property = property;
 }
 public PropertyNotSupportedException(string message, PropertyId property)
     : base(message)
 {
     this.Property = property;
 }
Beispiel #6
0
 public PropertyNotCachedException(PropertyId property)
     : base(string.Format(DefaultMessageWithData, property))
 {
     this.Property = property;
 }
 public static PatternId GetOrCreate(int id, string name, PropertyId availabilityProperty)
 {
     return(Cache.GetOrAdd(id, x => new PatternId(x, name, availabilityProperty)));
 }
 private PatternId(int id, string name, PropertyId availabilityProperty)
 {
     this.Id   = id;
     this.Name = name;
     this.AvailabilityProperty = availabilityProperty;
 }
 /// <inheritdoc/>
 public void HandlePropertyChangedEvent(AutomationElement sender, PropertyId propertyId, object newValue)
 {
     this.callAction(sender, propertyId, newValue);
 }
 /// <summary>
 /// Gets the desired property value. Ends in an exception if the property is not supported or not cached.
 /// </summary>
 public object GetPropertyValue(PropertyId property)
 {
     return(this.GetPropertyValue <object>(property));
 }
 /// <summary>
 /// Tries to get the property value.
 /// Returns false and sets a default value if the property is not supported.
 /// </summary>
 public bool TryGetPropertyValue(PropertyId property, out object value)
 {
     return(this.TryGetPropertyValue <object>(property, out value));
 }
 protected AutomationProperty <T> GetOrCreate <T>(ref AutomationProperty <T> val, PropertyId propertyId)
 {
     return(val ?? (val = new AutomationProperty <T>(propertyId, this.BasicAutomationElement)));
 }
 /// <summary>
 /// Method to check if the element supports the given property via UIA method.
 /// Does not work with cached elements and might be unreliable.
 /// </summary>
 public bool IsPropertySupportedDirect(PropertyId property)
 {
     return(this.GetSupportedPropertiesDirect().Contains(property));
 }
Beispiel #14
0
 public PropertyCondition(PropertyId property, object value)
     : this(property, value, PropertyConditionFlags.None)
 {
 }
Beispiel #15
0
 public PropertyCondition(PropertyId property, object value, PropertyConditionFlags propertyConditionFlags)
 {
     this.Property = property;
     this.Value    = value;
     this.PropertyConditionFlags = propertyConditionFlags;
 }
Beispiel #16
0
 public static bool TryGet(int id, out PropertyId result)
 {
     return(Cache.TryGetValue(id, out result));
 }