示例#1
0
        private void Init(StringOption option)
        {
            _option      = option;
            _adjustedFmt = string.IsNullOrEmpty(_option.Format) ? null : _option.Format;

            if (_adjustedFmt != null)
            {
                StringBuilder buffer = new StringBuilder();

                int index          = 0;
                int valueCharCount = 0;
                while (valueCharCount < _option.MaximumLength)
                {
                    if (index == _adjustedFmt.Length) // re-start over the format index
                    {
                        if (valueCharCount == 0)
                        {
                            break;
                        }
                        index = 0;
                    }

                    Char c = _adjustedFmt[index++];
                    if (c == '#')
                    {
                        valueCharCount++;
                    }

                    buffer.Append(c);
                }

                _adjustedFmt = (valueCharCount > 0)? buffer.ToString(): null;
            }

            CharcterType ct = (CharcterType)Zen.Utilities.Generics.EnumConverter.ToBitFlag(_option.CharcterTypes);

            _useLetter      = (ct & CharcterType.Letter) == CharcterType.Letter;
            _useDigit       = (ct & CharcterType.Digit) == CharcterType.Digit;
            _usePunctuation = (ct & CharcterType.Punctuation) == CharcterType.Punctuation;
        }
示例#2
0
 public RandomString(StringOption option)
 {
     Init(option);
 }