コード例 #1
0
ファイル: Kit-Mask.cs プロジェクト: Daoting/dt
        /// <summary>
        /// 解析Regular简单正则表达式
        /// </summary>
        /// <param name="p_srcValue">数据值</param>
        /// <param name="p_mask">掩码格式</param>
        /// <param name="p_placeHolder">占位符样式</param>
        /// <param name="p_saveLiteral">是否保存掩码后的文字</param>
        /// <returns>格式字符串</returns>
        public static string ParseRegularMask(object p_srcValue, string p_mask, char p_placeHolder, bool p_saveLiteral)
        {
            if (p_saveLiteral)
            {
                return(p_srcValue.ToString());
            }
            LegacyMaskInfo info = LegacyMaskInfo.GetRegularMaskInfo(p_mask, CultureInfo.CurrentCulture);

            return(ParseLegacy(p_srcValue, p_mask, p_placeHolder, info));
        }
コード例 #2
0
        /// <summary>
        /// 根据掩码属性创建编辑器的掩码员
        /// </summary>
        /// <returns></returns>
        MaskManager CreateDefaultMaskManager()
        {
            // 区域信息
            CultureInfo maskCulture = _owner.MaskCulture;

            if (maskCulture == null)
            {
                maskCulture = CultureInfo.CurrentCulture;
            }

            // 掩码表达式
            string str = _owner.Mask;

            if (str == null)
            {
                str = "";
            }

            // 根据掩码属性创建掩码管理者
            switch (_owner.MaskType)
            {
            case MaskType.DateTime:
                return(new DateTimeMaskManager(str, false, maskCulture, _owner.AllowNullInput));

            case MaskType.DateTimeAdvancingCaret:
                return(new DateTimeMaskManager(str, true, maskCulture, _owner.AllowNullInput));

            case MaskType.Numeric:
                return(new NumericMaskManager(str, maskCulture, _owner.AllowNullInput));

            case MaskType.RegEx:
                if (_owner.IgnoreBlank && (str.Length > 0))
                {
                    str = "(" + str + ")?";
                }
                return(new RegExpMaskManager(str, false, _owner.AutoComplete != AutoCompleteType.None, _owner.AutoComplete == AutoCompleteType.Optimistic, _owner.ShowPlaceHolder, _owner.PlaceHolder, maskCulture));

            case MaskType.Regular:
                return(new LegacyMaskManager(LegacyMaskInfo.GetRegularMaskInfo(str, maskCulture), _owner.PlaceHolder, _owner.SaveLiteral, _owner.IgnoreBlank));

            default:
                return(new LegacyMaskManager(LegacyMaskInfo.GetSimpleMaskInfo(str, maskCulture), _owner.PlaceHolder, _owner.SaveLiteral, _owner.IgnoreBlank));
            }
        }