Ejemplo n.º 1
0
        /// <summary>
        /// 根据层级数组检索子对象
        /// 获取倒数第二级的子对象时会返回 (int32)1 ???
        /// </summary>
        /// <param name="target">容器对象</param>
        /// <param name="layers">层级数组</param>
        /// <returns></returns>
        public static IAccessible GetAccessibleByLayers(this IAccessible target, int[] layers)
        {
            Console.WriteLine($"获取对象 {target.GetHashCode().ToString("X")} 指定层级 {string.Join(", ", layers)} 的对象...");
            IAccessible CurrentAccessible = target;

            foreach (int layer in layers)
            {
                CurrentAccessible = CurrentAccessible.GetChild(layer);
                if (CurrentAccessible == null)
                {
                    return(null);
                }
            }
            return(CurrentAccessible);
        }