public object GetCurrentPropertyValue(AutomationProperty property, bool ignoreDefaultValue) { Validate.ArgumentNotNull(parameter: property, parameterName: nameof(property)); var propertyValueVariant = new Variant(); try { propertyValueVariant = IUIAutomationElement.GetCurrentPropertyValueEx(propertyId: property.Id, ignoreDefaultValue: Convert.ToInt32(value: ignoreDefaultValue)); } catch (COMException ex) { } return(UiaConvert.ConvertPropertyValue(property: property, propertyValueVariant: propertyValueVariant)); }
/// <summary> /// Get Property value safely /// </summary> /// <param name="element"></param> /// <param name="id"></param> /// <returns></returns> private static dynamic GetPropertyValue(IUIAutomationElement element, int id) { dynamic value = null; try { dynamic temp = ShouldGetPropertyValueNoDefault(id) ? element.GetCurrentPropertyValueEx(id, 1 /*true*/) : element.GetCurrentPropertyValue(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 GetPropertyValue(IUIAutomationElement element, int id) { dynamic value = null; try { dynamic temp = ShouldGetPropertyValueNoDefault(id) ? element.GetCurrentPropertyValueEx(id, 1 /*true*/) : element.GetCurrentPropertyValue(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; }