Example #1
0
        /// <summary>
        /// Gets a random identifier based on the specified template.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="order">The order.</param>
        /// <param name="separator">The separator.</param>
        /// <param name="forceSingleLetter">if set to <c>true</c> [force single letter].</param>
        /// <param name="lengthRestriction">The length restriction.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="ArgumentOutOfRangeException">template - null</exception>
        public string Get(IdentifierTemplate template, NameOrderingStyle order = DefaultOrderStyle, string separator = " ", bool forceSingleLetter = false, int lengthRestriction = 0)
        {
            switch (template)
            {
            case IdentifierTemplate.AnyTwoComponents:
                return(this.GetRandomTwo(order, separator, forceSingleLetter, lengthRestriction));

            case IdentifierTemplate.AnyThreeComponents:
                return(this.Get(this.GetRandomAdjective() | this.GetRandomNoun() | IdentifierComponents.FirstName, order, separator, forceSingleLetter, lengthRestriction));

            case IdentifierTemplate.BobTheBuilder:
                return(this.Get(IdentifierComponents.Profession | IdentifierComponents.FirstName, order, separator, forceSingleLetter, lengthRestriction));

            case IdentifierTemplate.PeppaPig:
                return(this.Get(IdentifierComponents.Animal | IdentifierComponents.FirstName, order, separator, forceSingleLetter, lengthRestriction));

            case IdentifierTemplate.SilentBob:
                return(this.Get(IdentifierComponents.Adjective | IdentifierComponents.FirstName, order, separator, forceSingleLetter, lengthRestriction));

            case IdentifierTemplate.GitHub:
                return(this.Get(IdentifierComponents.Adjective | IdentifierComponents.Noun, order, separator, forceSingleLetter, lengthRestriction));

            default:
                throw new ArgumentOutOfRangeException(nameof(template), template, null);
            }
        }
Example #2
0
        private string Get(IdentifierComponents components, NameOrderingStyle orderStyle, string separator, char?forcedSingleLetter)
        {
            StringBuilder sb = new StringBuilder();

            switch (orderStyle)
            {
            case NameOrderingStyle.SilentBobStyle:
                return(this.GetSilentBobOrder(components, separator, sb, forcedSingleLetter));

            case NameOrderingStyle.BobTheBuilderStyle:
                return(this.GetBobTheBuilderOrder(components, separator, sb, forcedSingleLetter));

            default:
                throw new ArgumentOutOfRangeException(nameof(orderStyle), orderStyle, null);
            }
        }
Example #3
0
        private string GetRandomTwo(NameOrderingStyle order, string separator = " ", bool forceSingleLetter = false, int lengthRestriction = 0)
        {
            var setNumber = this.randomIndex.Get(3);

            switch (setNumber)
            {
            case 0:
                return(this.Get(this.GetRandomNoun() | IdentifierComponents.FirstName, order, separator, forceSingleLetter, lengthRestriction));

            case 1:
                return(this.Get(this.GetRandomAdjective() | IdentifierComponents.FirstName, order, separator, forceSingleLetter, lengthRestriction));

            case 2:
                return(this.Get(this.GetRandomAdjective() | this.GetRandomNoun(), order, separator, forceSingleLetter, lengthRestriction));

            default:
                return(this.Get(this.GetRandomAdjective() | this.GetRandomNoun(), order, separator, forceSingleLetter, lengthRestriction));
            }
        }
Example #4
0
 /// <summary>
 /// Gets a random identifier based on the specified template.
 /// <para>Bear in mind that enumerating the result set multiple times will yield different results</para>
 /// </summary>
 /// <param name="numberOfNamesToReturn"></param>
 /// <param name="template">The template.</param>
 /// <param name="order">The order.</param>
 /// <param name="separator">The separator.</param>
 /// <param name="forceSingleLetter">if set to <c>true</c> [force single letter].</param>
 /// <param name="lengthRestriction">The length restriction.</param>
 /// <returns>System.String.</returns>
 /// <exception cref="ArgumentOutOfRangeException">template - null</exception>
 public IEnumerable <string> Get(int numberOfNamesToReturn, IdentifierTemplate template, NameOrderingStyle order = DefaultOrderStyle, string separator = " ", bool forceSingleLetter = false, int lengthRestriction = 0)
 {
     for (int i = 0; i < numberOfNamesToReturn; i++)
     {
         yield return(this.Get(template, order, separator, forceSingleLetter, lengthRestriction));
     }
 }
Example #5
0
        /// <summary>
        /// Gets a random identifier based on the settings
        /// </summary>
        /// <param name="components">The components.</param>
        /// <param name="orderStyle">The order style.</param>
        /// <param name="separator">The separator between the words.</param>
        /// <param name="forceSingleLetter">if set to <c>true</c> all words of the result will start with the same letter, e.g. Irena The Idiosyncratic, Tammara The Twinkly or Quintana The Qualified</param>
        /// <param name="lengthRestriction">Maximum number of characters in the returned string</param>
        /// <returns>System.String.</returns>
        /// <exception cref="ArgumentOutOfRangeException">orderStyle - null</exception>
        public string Get(IdentifierComponents components = IdentifierComponents.Adjective | IdentifierComponents.Noun, NameOrderingStyle orderStyle = DefaultOrderStyle, string separator = " ", bool forceSingleLetter = false, int lengthRestriction = 0)
        {
            char?forcedSingleLetter = Helpers.GetForcedSingleCharacter(forceSingleLetter, this.randomIndex);
            int  attempt            = 0;

            while (true) //if there is a length restriction, retry a couple of times. If the string is still too long, just trim it
            {
                attempt++;
                var name = this.Get(components, orderStyle, separator, forcedSingleLetter);
                if (lengthRestriction <= 0)
                {
                    return(name);
                }
                else if (name.Length <= lengthRestriction)
                {
                    return(name);
                }

                if (attempt >= 100)
                {
                    return(name.Remove(lengthRestriction));
                }
            }
        }
Example #6
0
 /// <summary>
 /// Gets an IEnumerable of random identifiers based on the settings
 /// <para>Bear in mind that enumerating the result set multiple times will yield different results</para>
 /// </summary>
 /// <param name="numberOfNamesToReturn">How many outputs to get</param>
 /// <param name="components">The components.</param>
 /// <param name="orderStyle">The order style.</param>
 /// <param name="separator">The separator between the words.</param>
 /// <param name="forceSingleLetter">if set to <c>true</c> all words of the result will start with the same letter, e.g. Irena The Idiosyncratic, Tammara The Twinkly or Quintana The Qualified</param>
 /// <param name="lengthRestriction">Maximum number of characters in the returned string</param>
 /// <returns>System.String.</returns>
 /// <exception cref="ArgumentOutOfRangeException">orderStyle - null</exception>
 public IEnumerable <string> Get(int numberOfNamesToReturn, IdentifierComponents components = IdentifierComponents.Adjective | IdentifierComponents.Noun, NameOrderingStyle orderStyle = DefaultOrderStyle, string separator = " ", bool forceSingleLetter = false, int lengthRestriction = 0)
 {
     for (int i = 0; i < numberOfNamesToReturn; i++)
     {
         yield return(this.Get(components, orderStyle, separator, forceSingleLetter, lengthRestriction));
     }
 }