DEV Community

Amina Elsheikh
Amina Elsheikh

Posted on • Updated on

Data Generator Nuget Package

Objective

This is a cross platform NET Standard 2.0 generator library containing a bunch of generating codes that I needed while developing apps. I hope it will save your development time.

About

This library is one of DEFC utilities packages that contains several types of data generating, to help the developers minify their codes in easy way with no time. Through this package can :

  • Generate GUID.
  • Generate Random Symbol.
  • Generate Unique Code and compare it to a list.
  • Generate Random String with specific length and choose if it is lowercase or uppercase or both.
  • Generate Random Number between min and max.
  • Generate any Random Code.

Example

Install-Package DEFC.Util.Generator --version 1.0.0
Enter fullscreen mode Exit fullscreen mode
using DEFC.Util;
Enter fullscreen mode Exit fullscreen mode
public static string GeneratePassword()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(Generator.RandomString(2, true));//2 lower case random letters
            builder.Append(Generator.RandomString(3, false));//3 uppper case random letters
            builder.Append(Generator.RandomSymbol());//random symbol
            builder.Append(Generator.RandomNumber(1000, 9999));//random number between 1000 and 9999

            return builder.ToString();
        }
        public static string GenerateUser(List<string> ListToCheck)
        {
            char[] CharacterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890".ToCharArray();
            //Generate user with 20 characters length from a set of character and check if it is already exists in a list of users    

            return Generator.UniqueCode(CharacterSet, 20, ListToCheck);   
        }         
        public static string GenerateClientID()
        {
            char[] CharacterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890".ToCharArray();

            StringBuilder builder = new StringBuilder();
            builder.Append(Generator.RandomCode(CharacterSet,8));//8 random characters
            builder.Append("-");
            builder.Append(Generator.RandomCode(CharacterSet, 4));//4 random characters
            builder.Append("-");
            builder.Append(Generator.RandomCode(CharacterSet, 12));//12 random characters
            return builder.ToString();
        }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)