System.Windows.Automation.Text.TextPatternRange.GetAttributeValue C# (CSharp) Method

GetAttributeValue() public method

public GetAttributeValue ( AutomationTextAttribute attribute ) : object
attribute AutomationTextAttribute
return object
        public object GetAttributeValue(AutomationTextAttribute attribute)
        {
            Utility.ValidateArgumentNonNull(attribute, "attribute");
            try
            {
                PropertyTypeInfo info;
                if (!Schema.GetPropertyTypeInfo(attribute, out info))
                {
                    throw new ArgumentException("Unsupported Attribute");
                }
                object valueAsObject = this._range.GetAttributeValue(attribute.Id);
                if (info.Type.IsEnum && (valueAsObject is int))
                {
                    return Enum.ToObject(info.Type, (int)valueAsObject);
                }
                if ((valueAsObject != AutomationElement.NotSupported) && (info.ObjectConverter != null))
                {
                    valueAsObject = info.ObjectConverter(valueAsObject);
                }
                return valueAsObject;
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }

Usage Example

Ejemplo n.º 1
0
        //---------------------------------------------------------------------------
        // Wrapper for TextPatternRange.GetAttributeValue Method
        //---------------------------------------------------------------------------
        internal void Range_GetAttributeValue(TextPatternRange callingRange, AutomationTextAttribute attrib, ref object val, Type expectedException, CheckType checkType)
        {
            string call = "";
            if (attrib != null)
                call = "TextPatternRange.GetAttributeValue(" + Helpers.GetProgrammaticName(attrib) + ")";
            else
                call = "TextPatternRange.GetAttributeValue(NULL)";
            Comment("---Calling " + call);

            if (callingRange == null)
                throw new ArgumentNullException(call + " requires non-NULL TextPatterncallingRange");

            try
            {
                val = callingRange.GetAttributeValue(attrib);

                if (val.Equals(AutomationElement.NotSupported))
                {
                    string msg = Helpers.GetProgrammaticName(attrib) + " not supported by control";
                    Comment(msg);
                }
            }
            catch (Exception actualException)
            {
                if (Library.IsCriticalException(actualException))
                    throw;

                TestException(expectedException, actualException, call, checkType);
                return;
            }
            TestNoExceptionQuiet(expectedException, call, checkType);
        }