Exemple #1
0
        /// <summary>
        /// 尝试为输入控件设置值
        /// </summary>
        /// <param name="input">输入控件</param>
        /// <param name="value">要设置的值</param>
        /// <returns>是否成功</returns>
        /// <remarks>对于密码框或不存在值吻合选项的输入组,此方法会设置失败并返回false</remarks>
        /// <exception cref="System.NotSupportedException">不被支持的输入控件</exception>
        public static bool TrySetValue(this IHtmlInputControl input, string value)
        {
            if (input == null)
            {
                return(false);
            }

            var textControl = input as IHtmlTextControl;

            if (textControl != null)
            {
                return(TrySetValue(textControl, value));
            }

            var group = input as IHtmlGroupControl;

            if (group != null)
            {
                return(TrySetValue(group, value));
            }

            throw new NotSupportedException(string.Format("名为 \"{0}\" 输入控件的类型 \"{1}\" 不受支持。", input.Name, input.GetType().FullName));
        }