public object GetCachedPropertyValue(AutomationProperty property, bool ignoreDefaultValue) { Validate.ArgumentNotNull(parameter: property, parameterName: nameof(property)); var cachedPropertyValueEx = IUIAutomationElement.GetCachedPropertyValueEx(propertyId: property.Id, ignoreDefaultValue: Convert.ToInt32(value: ignoreDefaultValue)); return(UiaConvert.ConvertPropertyValue(property: property, propertyValueVariant: cachedPropertyValueEx)); }
/// <summary> /// Get Property value safely /// </summary> /// <param name="element"></param> /// <param name="id"></param> /// <returns></returns> private static dynamic GetPropertyValueFromCache(IUIAutomationElement element, int id) { dynamic value = null; try { dynamic temp = ShouldGetPropertyValueNoDefault(id) ? element.GetCachedPropertyValueEx(id, 1 /*true*/) : element.GetCachedPropertyValue(id); value = ConvertVariantAsNeeded(temp); } catch { value = null; } return(value); }
/// <summary> /// Get Property value safely /// </summary> /// <param name="element"></param> /// <param name="id"></param> /// <returns></returns> private static dynamic GetPropertyValueFromCache(IUIAutomationElement element, int id) { dynamic value = null; try { dynamic temp = ShouldGetPropertyValueNoDefault(id) ? element.GetCachedPropertyValueEx(id, 1 /*true*/) : element.GetCachedPropertyValue(id); value = ConvertVariantAsNeeded(temp); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); value = null; } #pragma warning restore CA1031 // Do not catch general exception types return value; }