Show / Hide Table of Contents

Class Utilities

Common utility class contains shared methods to enhance the generic works

Inheritance
Object
Utilities
Namespace: AxaFrance.WebEngine
Assembly: AxaFrance.WebEngine.dll
Syntax
public static class Utilities

Methods

| Edit this page View Source

ExtractDateFromText(String)

Turn the string "JJ/MM/AAAA" into a date

Declaration
public static DateTime ExtractDateFromText(string text)
Parameters
Type Name Description
String text

The string to convert

Returns
Type Description
DateTime

The date represented by the String. If no date is contained in the string or wrong format, the current date is returned

| Edit this page View Source

GenerateEmail(String, String, Boolean, String)

Return an email based on first and last name. No transformation is done on last name and first names. The email is considered unique as the date is injected in the construction.

Declaration
public static string GenerateEmail(string lastname, string firstname, bool isUnique = true, string domain = "test.com")
Parameters
Type Name Description
String lastname

The last name.

String firstname

The first name.

Boolean isUnique

Indicates if the generated email must be unique or not. Default: true

String domain

The domain of the generated mail. Default: gmail.com

Returns
Type Description
String

An email.

| Edit this page View Source

GeneratePhoneNumber(String)

Return a phone number composed by a fixed base and the 4 last digits randomly generated.

Declaration
public static string GeneratePhoneNumber(string numberBase = "01000")
Parameters
Type Name Description
String numberBase

The first part of the phone number. Default: 010000 (french format)

Returns
Type Description
String

A phone number

| Edit this page View Source

GetRandomItemFromEnvironmentVariable(String, Char)

Picks up a random value from an environment variable containing a list of values.

Declaration
public static string GetRandomItemFromEnvironmentVariable(string variable, char separator = ';')
Parameters
Type Name Description
String variable

The name of the environment variable

Char separator

The list separator used to define the environment variable. Default: ';'

Returns
Type Description
String

String

| Edit this page View Source

GetRandomLetter()

Return a random letter (uppercase).

Declaration
public static string GetRandomLetter()
Returns
Type Description
String

String

| Edit this page View Source

GetRandomNumber(Int32)

Generate a random number between 0 and the value.

Declaration
public static int GetRandomNumber(int val)
Parameters
Type Name Description
Int32 val

The max value.

Returns
Type Description
Int32

Integer

| Edit this page View Source

GetRandomStringFromList(Object[])

Randomly select an item from a list. If the field has single or double quotes, quotes are removed.

Declaration
public static object GetRandomStringFromList(object[] items)
Parameters
Type Name Description
Object[] items

List of items

Returns
Type Description
Object

Picked-up item

| Edit this page View Source

LoremIpsum(Int32, Int32, Int32, Int32, Int32)

Generates a Lorem Ipsum text.

Declaration
public static string LoremIpsum(int minWords, int maxWords, int minSentences, int maxSentences, int numParagraphs)
Parameters
Type Name Description
Int32 minWords

The min number of words in the generated text.

Int32 maxWords

The max number of words in the generated text.

Int32 minSentences

The min number of sentences in the generated text.

Int32 maxSentences

The max number of sentences in the generated text.

Int32 numParagraphs

The number of paragraphs in the generated text.

Returns
Type Description
String

A Lorem Ipsum string of the defined size.

| Edit this page View Source

SaveFile(String, String)

Saves the content into a file

Declaration
public static void SaveFile(string filename, string content)
Parameters
Type Name Description
String filename

The file name to be saved.

String content

The content to save.

| Edit this page View Source

ShiftDateByDuration<T>(String, T)

Returns a new date calculated from a given date and a duration.

The duration is positive or negative with a unity.

The unity is (D or J), M or (Y or A) representing respectively : a duration expressed in days, month or year.

The sign indicates that the calculated date must be in the past (negative) or in the future (positive).

The start date is optional. If omitted, the current date is considered.

If passed as argument, the start date must be either a string with the following format "DD/MM/YYYY" or a DateTime or even a "differential" date like the duration itself.

In this last case, the startDate is recalculated from the current date.

Example:

MoveDateByDuration("7D"): returns Today+7 days.

MoveDateByDuration("-6M", DateTime(2017, 6, 25)): should return 25th of december 2016

MoveDateByDuration("-6M", "25/06/2017"): should return 25th of december 2016.

MoveDateByDuration("2D", "1D"): the day in 3 days (2 days from tomorrow).

Declaration
public static DateTime ShiftDateByDuration<T>(string duration, T startDate)
Parameters
Type Name Description
String duration
T startDate
Returns
Type Description
DateTime

The calcuated Date of type System.DateTime

Type Parameters
Name Description
T
  • Edit this page
  • View Source
In this article
Back to top Copyright ® 2016-2024 AXA France, All rights reserved.