Utilities

Getting Started

The VersaTul Utilities project provides a variety of commonly used helper methods to help with the rapid development process.

Installation

To use VersaTul Utilities, first install it using nuget:

PM> NuGet\Install-Package VersaTul.Utilities -Version latest

Main Components

  1. ICollectionUtility<T> : Represent a set of functionality that can operate on collections.

  2. IEnumParser<T> : Represents utility methods that can be use for quickly operating on Enums.

  3. IGenerator : Represents a set of methods that can be used to produces a sequence of numbers or letters that meet certain statistical requirements for randomness.

  4. INullFiltering : Represents utility methods that can be use for operating on fillering Null values.

  5. IUtility : Represent a set of generic functionality.

  6. CommonUtility : Concrete implementation of the above interfaces.

Functional Summary

  1. IEnumerable<IEnumerable<T>> ICollectionUtility<T>.MakeBatches(IEnumerable<T> entities, int batchSize) : Distributes the given collection and arrange the set into sets or groups..

  2. T IEnumParser<T>.Parse(int value) : Converts the numeric value of one or more enumerated constants to an equivalent enumerated object..

  3. T IEnumParser<T>.Parse(string value) : Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object.

  4. int IEnumParser<T>.Parse(T value) : Returns a integer of the specified type and whose value is equivalent to the specified enumType..

  5. string IEnumParser<T>.ParseToString(T value) : Returns a string of the specified type and whose value is equivalent to the specified enumType..

  6. string IGenerator.RandomString(int length, string allowedChars = “ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”); : Returns a non-negative random string for the given length for the allowed characters.

  7. T INullFiltering.DBNullFilter<T>(object value) : Checks for DBNull value then returns an object of a specified type whose value is equivalent to a specified object..

  8. T INullFiltering.NullFilter<T>(object value) : Checks for Null value then returns an object of a specified type whose value is equivalent to a specified object.

  9. T INullFiltering.NullOrEmptyFilter<T>(string value) : Checks for Null or and Empty string then returns an object of a specified type whose value is equivalent to a specified object.

Code Examples

Random Generator Example
using VersaTul.Utilities;
using VersaTul.Utilities.Contracts;

IGenerator generator = new CommonUtility();

// variable length strings
Console.WriteLine(generator.RandomString(10));
Console.WriteLine(generator.RandomString(20));
Console.WriteLine(generator.RandomString(40));
Console.WriteLine(generator.RandomString(5));
Console.WriteLine(generator.RandomString(3));
Console.WriteLine(generator.RandomString(6));
Console.WriteLine(generator.RandomString(80));
Null Filtering Examples
using VersaTul.Utilities;
using VersaTul.Utilities.Contracts;

INullFiltering nullFiltering = new CommonUtility();

Console.WriteLine(nullFiltering.NullFilter<int>(1)); //output 1
Console.WriteLine(nullFiltering.NullFilter<string>("This is my string")); //output "This is my string"


Console.WriteLine(nullFiltering.NullFilter<int>(null)); // output 0
Console.WriteLine(nullFiltering.NullFilter<string>(null)); // output empty
Enum Parser Examples
using VersaTul.Utilities;
using VersaTul.Utilities.Contracts;

IEnumParser<Color> enumParser = new EnumParser<Color>();

Console.WriteLine(enumParser.Parse(Color.Red)); //output value 1
Console.WriteLine(enumParser.ParseToString(Color.Red)); //output string "Red"
Console.WriteLine(enumParser.Parse("Green")); //output Color.Green
Console.WriteLine(enumParser.Parse(3)); //output Color.Blue
Console.WriteLine(enumParser.Parse("Green") == Color.Green); //output true
Console.WriteLine(enumParser.Parse(3) == Color.Blue); //output  true

public enum Color
{
    None, Red, Green, Blue
}

Changelog