Esempio n. 1
0
        private string Construct(SysTokenParts parts, StringBuilder sb = null)
        {
            sb ??= new StringBuilder();

            if ((parts & SysTokenParts.Prefix) != 0 && _options.Prefix != null)
            {
                sb.Append(_options.Prefix);
            }

            if ((parts & SysTokenParts.PrefixSeparator) != 0 && _options.PrefixSeparator != null)
            {
                sb.Append(_options.PrefixSeparator);
            }

            if ((parts & SysTokenParts.Payload) != 0)
            {
                sb.Append(_payload);
            }

            if ((parts & SysTokenParts.PostfixSeparator) != 0 && _options.PostfixSeparator != null)
            {
                sb.Append(_options.PostfixSeparator);
            }

            if ((parts & SysTokenParts.Postfix) != 0 && _options.Postfix != null)
            {
                sb.Append(_options.Postfix);
            }

            return((sb.Length > 0) ? sb.ToString() : null);
        }
Esempio n. 2
0
        public void CopyTo(StringBuilder sb, RandomTokenParts parts)
        {
            if (sb is null)
            {
                throw new ArgumentNullException(nameof(sb));
            }

            SysTokenParts convertTokenParts()
            {
                SysTokenParts sysParts = SysTokenParts.None;

                if ((parts & RandomTokenParts.Prefix) != 0)
                {
                    sysParts |= (SysTokenParts.Prefix | SysTokenParts.PrefixSeparator);
                }

                if ((parts & RandomTokenParts.Payload) != 0)
                {
                    sysParts |= SysTokenParts.Payload;
                }

                if ((parts & RandomTokenParts.Postfix) != 0)
                {
                    sysParts |= (SysTokenParts.PostfixSeparator | SysTokenParts.Postfix);
                }

                return(sysParts);
            }

            Construct(convertTokenParts(), sb);
        }