Table of Contents

Class ExtensionsLib

Namespace
PHCLibrary
Assembly
PHCLibrary.dll
public class ExtensionsLib
ExtensionsLib

Fields

EncryptionKey

public const string EncryptionKey = "IsEncrypt_"

Field Value

string

Indentation

public const string Indentation = "  "

Field Value

string

Methods

AddApostrophes(string)

Add apostrophe in the beggining and end of the word.

[Extension]
public static string AddApostrophes(this string source)

Parameters

Nome Tipo Descrição
source string

Returns

string

AddBrackets(string)

Add [ ... ] to each element that the string contains, for example 'test' will be '[test]' and 'alias.test' will be '[alias].[test]'

[Extension]
public static string AddBrackets(this string item)

Parameters

Nome Tipo Descrição
item string

Returns

string

Remarks

Is a useful function for formatting text to send to SQL

AddIf<T>(List<T>, T)

Adds the element of the specified collection to the end of the source if element is not nothing.

[Extension]
public static void AddIf<T>(this List<T> source, T item)

Parameters

Nome Tipo Descrição
source List<T>
item T

Type Parameters

T

AddItens<T>(List<T>, params T[])

Adds several elements of the specified collection to the end of the source.

[Extension]
public static void AddItens<T>(this List<T> source, params T[] itens)

Parameters

Nome Tipo Descrição
source List<T>
itens T[]

Type Parameters

T

AddPercentages(string)

Add percentages in the beggining and end of the word. Useful to do "Like" queries

[Extension]
public static string AddPercentages(this string source)

Parameters

Nome Tipo Descrição
source string

Returns

string

AddRangeIf<T>(List<T>, IEnumerable<T>)

Adds the elements of the specified collection to the end of the source if have elements.

[Extension]
public static void AddRangeIf<T>(this List<T> source, IEnumerable<T> Collection)

Parameters

Nome Tipo Descrição
source List<T>
Collection IEnumerable<T>

Type Parameters

T

AddTime(DateTime, string)

[Extension]
public static DateTime AddTime(this DateTime source, string time)

Parameters

Nome Tipo Descrição
source DateTime
time string

Returns

DateTime

AddToParent<T>(T, ICollection<T>)

Adds an item to the parent.

[Extension]
public static T AddToParent<T>(this T source, ICollection<T> parent)

Parameters

Nome Tipo Descrição
source T
parent ICollection<T>

Returns

T

Type Parameters

T

AddWorkingDays(DateTime, int)

[Extension]
public static DateTime AddWorkingDays(this DateTime source, int days)

Parameters

Nome Tipo Descrição
source DateTime
days int

Returns

DateTime

AppendChildIf(XElement, XElement)

[Extension]
public static XElement AppendChildIf(this XElement source, XElement newChild)

Parameters

Nome Tipo Descrição
source XElement
newChild XElement

Returns

XElement

AppendLines(StringBuilder, IList<string>, string)

Execute a For Each in the received list and execute an AppendLine to StringBuilder, using to avoid writing the cycle

[Extension]
public static StringBuilder AppendLines(this StringBuilder msgItem, IList<string> lines, string indent = "")

Parameters

Nome Tipo Descrição
msgItem StringBuilder
lines IList<string>
indent string

Returns

StringBuilder

BreakLines(string)

Replaces new line character

[Extension]
public static string BreakLines(this string texto)

Parameters

Nome Tipo Descrição
texto string

Returns

string

Clone(Uri)

[Extension]
public static Uri Clone(this Uri value)

Parameters

Nome Tipo Descrição
value Uri

Returns

Uri

Clone(HttpContext)

[Extension]
public static IWSContext Clone(this HttpContext contextItem)

Parameters

Nome Tipo Descrição
contextItem HttpContext

Returns

IWSContext

ConvertFromBase64String(string)

Get the UTF8 string from Base64

[Extension]
public static string ConvertFromBase64String(this string source)

Parameters

Nome Tipo Descrição
source string

Returns

string

DecimalFormatter(decimal, int)

[Extension]
public static string DecimalFormatter(this decimal source, int decimalPlaces)

Parameters

Nome Tipo Descrição
source decimal
decimalPlaces int

Returns

string

DecimalTruncate(decimal, int)

[Extension]
public static decimal DecimalTruncate(this decimal source, int decimalPlacesToTruncate)

Parameters

Nome Tipo Descrição
source decimal
decimalPlacesToTruncate int

Returns

decimal

Decrypt(string)

[Extension]
public static string Decrypt(this string value)

Parameters

Nome Tipo Descrição
value string

Returns

string

DefaultIfEmpty(DateTime, Func<DateTime>)

[Extension]
public static DateTime DefaultIfEmpty(this DateTime source, Func<DateTime> defaultValueFunc)

Parameters

Nome Tipo Descrição
source DateTime
defaultValueFunc Func<DateTime>

Returns

DateTime

DefaultIfNothing<TSource>(TSource, Func<TSource>)

[Extension]
public static TSource DefaultIfNothing<TSource>(this TSource source, Func<TSource> defaultValueFunction)

Parameters

Nome Tipo Descrição
source TSource
defaultValueFunction Func<TSource>

Returns

TSource

Type Parameters

TSource

DoubleTruncate(double, int)

[Extension]
public static double DoubleTruncate(this double source, int decimalPlacesToTruncate)

Parameters

Nome Tipo Descrição
source double
decimalPlacesToTruncate int

Returns

double

Encrypt(string)

[Extension]
public static string Encrypt(this string value)

Parameters

Nome Tipo Descrição
value string

Returns

string

EncryptToLog(string)

[Extension]
public static string EncryptToLog(this string value)

Parameters

Nome Tipo Descrição
value string

Returns

string

EndOfMonthDate(DateTime)

[Extension]
public static DateTime EndOfMonthDate(this DateTime value)

Parameters

Nome Tipo Descrição
value DateTime

Returns

DateTime

EpochFromDate(DateTime)

[Extension]
public static double EpochFromDate(this DateTime targetDate)

Parameters

Nome Tipo Descrição
targetDate DateTime

Returns

double

EqualsWithIgnoreCase(string, string)

Determines whether this string and a specified System.String object have the same value and ignore case for invariante culture.

[Extension]
public static bool EqualsWithIgnoreCase(this string source, string value)

Parameters

Nome Tipo Descrição
source string
value string

Returns

bool

FirstOrDefault<T>(IEnumerable<T>, Func<T>)

Returns the first element of a sequence, or a default value if the sequence contains no elements.

[Extension]
public static T FirstOrDefault<T>(this IEnumerable<T> source, Func<T> getDefaultValueFunction)

Parameters

Nome Tipo Descrição
source IEnumerable<T>
getDefaultValueFunction Func<T>

Returns

T

Type Parameters

T

FirstOrDefault<T>(IList)

[Extension]
public static T FirstOrDefault<T>(this IList list)

Parameters

Nome Tipo Descrição
list IList

Returns

T

Type Parameters

T

FirstOrDefault<T>(Task<IList>)

[Extension]
public static T FirstOrDefault<T>(this Task<IList> list)

Parameters

Nome Tipo Descrição
list Task<IList>

Returns

T

Type Parameters

T

Forget(Task)

Consumes a task and doesn't do anything with it. Useful for fire-and-forget calls to async methods within async methods

[Extension]
public static void Forget(this Task taskItem)

Parameters

Nome Tipo Descrição
taskItem Task

The task whose result is to be ignored.

Format(MethodParameter)

[Extension]
public static List<string> Format(this MethodParameter parameter)

Parameters

Nome Tipo Descrição
parameter MethodParameter

Returns

List<string>

Format(StackFrame[])

[Extension]
public static List<string> Format(this StackFrame[] frames)

Parameters

Nome Tipo Descrição
frames StackFrame[]

Returns

List<string>

Format(StackFrame[], string, string, int)

[Extension]
public static List<string> Format(this StackFrame[] frames, string sourceFileName, string sourceCaller, int sourceLineNumber)

Parameters

Nome Tipo Descrição
frames StackFrame[]
sourceFileName string
sourceCaller string
sourceLineNumber int

Returns

List<string>

Format(Exception, bool, string, string, int)

[Extension]
public static List<string> Format(this Exception ex, bool innerException, string filePath, string caller, int lineNumber)

Parameters

Nome Tipo Descrição
ex Exception
innerException bool
filePath string
caller string
lineNumber int

Returns

List<string>

Format(Exception, string, string, int)

[Extension]
public static List<string> Format(this Exception ex, string filePath, string caller, int lineNumber)

Parameters

Nome Tipo Descrição
ex Exception
filePath string
caller string
lineNumber int

Returns

List<string>

FormatWith(string, params object[])

Replaces the format item in a specified string with the string representation of a corresponding object in a specified array.

[Extension]
public static string FormatWith(this string format, params object[] args)

Parameters

Nome Tipo Descrição
format string

A composite format string.

args object[]

An object array that contains zero or more objects to format.

Returns

string

A copy of format in which the format items have been replaced by the string representation of the corresponding objects in args.

GetAndSetValueIfNothing<T>(ref T, Func<T>)

[Extension]
public static T GetAndSetValueIfNothing<T>(this ref T source, Func<T> getValue)

Parameters

Nome Tipo Descrição
source T
getValue Func<T>

Returns

T

Type Parameters

T

GetDateSeparator(string)

Get the date separator, example '01.02.2000' returns '.' and for example '01/02/2000' returns '/'

[Extension]
public static string GetDateSeparator(this string strDate)

Parameters

Nome Tipo Descrição
strDate string

Returns

string

GetDayEndOfMonth(DateTime)

[Extension]
public static int GetDayEndOfMonth(this DateTime value)

Parameters

Nome Tipo Descrição
value DateTime

Returns

int

GetDigits4(decimal)

[Extension]
public static int GetDigits4(this decimal value)

Parameters

Nome Tipo Descrição
value decimal

Returns

int

GetFirstAlias(string, string)

Get the first alias but not remove brackets

[Extension]
public static string GetFirstAlias(this string value, string separator = ".")

Parameters

Nome Tipo Descrição
value string
separator string

Returns

string

Remarks

'[test]' will return '[test]' and '[alias].[test]' will return '[alias]' and '[alias].[second].[test]' will be '[alias]'

GetFirstFieldName(string)

Get the first field name and remove brackets

[Extension]
public static string GetFirstFieldName(this string value)

Parameters

Nome Tipo Descrição
value string

Returns

string

Remarks

We expect that if we receive an alias string, the first is always the name of the entity or table, for example 'ft.name' or 'ft.addon1.name', in where we get name or addon1

GetLastAlias(string, string)

Get the last alias and remove brackets

[Extension]
public static string GetLastAlias(this string value, string separator = ".")

Parameters

Nome Tipo Descrição
value string
separator string

Returns

string

Remarks

'[test]' will return 'test' and '[alias].[test]' will return 'test' and '[alias].[second].[test]' will be 'test'

GetLines(string, StringSplitOptions)

Array of strings that were obtained, automatically searching for the separator character.

[Extension]
public static string[] GetLines(this string msgtext, StringSplitOptions splitOption = StringSplitOptions.None)

Parameters

Nome Tipo Descrição
msgtext string
splitOption StringSplitOptions

Returns

string[]

Remarks

The search will be performed using first the string 'vbCrLf' followed by 'vbLf' then 'vbCr' and finally if none exists for 'Environment.NewLine'. As soon as one of the separators is found, the text is divided and the function immediately returns the result, ignoring whether there are more other separators in the original text.

GetLocaleKeyMonth(DateTime)

[Extension]
public static string GetLocaleKeyMonth(this DateTime value)

Parameters

Nome Tipo Descrição
value DateTime

Returns

string

GetReplicated(string, int)

[Extension]
public static string GetReplicated(this string carater, int nCount)

Parameters

Nome Tipo Descrição
carater string
nCount int

Returns

string

GetSafeCurrencyFormat(string, ref string)

Transform the strinf into a safe currency format

[Extension]
public static string GetSafeCurrencyFormat(this string currencyValue, ref string decimalSeparator = null)

Parameters

Nome Tipo Descrição
currencyValue string
decimalSeparator string

Returns

string

Remarks

'€ 34,120.00' = '34120.00' ; '€ 34.120,00' = '34120.00'

GetSafeString(string)

[Extension]
public static string GetSafeString(this string value)

Parameters

Nome Tipo Descrição
value string

Returns

string

GetUtf8Bytes(string)

This function will return the UTF8 bytes of the string

[Extension]
public static byte[] GetUtf8Bytes(this string source)

Parameters

Nome Tipo Descrição
source string

Returns

byte[]

GetWords(string, StringSplitOptions)

[Extension]
public static string[] GetWords(this string msgtext, StringSplitOptions splitOption = StringSplitOptions.None)

Parameters

Nome Tipo Descrição
msgtext string
splitOption StringSplitOptions

Returns

string[]

HaveItens<T>(IEnumerable<T>)

Verify if the source not is null and if have values.

[Extension]
public static bool HaveItens<T>(this IEnumerable<T> source)

Parameters

Nome Tipo Descrição
source IEnumerable<T>

Returns

bool

Type Parameters

T

ISOtoDate(string)

Convert a iso string date yyyy-MM-dd into a datetime object but only the date

[Extension]
public static DateTime ISOtoDate(this string sDate)

Parameters

Nome Tipo Descrição
sDate string

Returns

DateTime

IsBetween<T>(T, T, T)

[Extension]
public static bool IsBetween<T>(this T item, T minValue, T maxValue) where T : IComparable

Parameters

Nome Tipo Descrição
item T
minValue T
maxValue T

Returns

bool

Type Parameters

T

IsDayEndOfMonth(DateTime)

[Extension]
public static bool IsDayEndOfMonth(this DateTime value)

Parameters

Nome Tipo Descrição
value DateTime

Returns

bool

IsDigit(char)

Whether the character is contained in the group {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}

[Extension]
public static bool IsDigit(this char value)

Parameters

Nome Tipo Descrição
value char

Returns

bool

IsFieldTagged(List<string>, string)

By default when fieldsTagged is empty we always assume that the field is tagged

[Extension]
public static bool IsFieldTagged(this List<string> fieldsTagged, string fieldName)

Parameters

Nome Tipo Descrição
fieldsTagged List<string>
fieldName string

Returns

bool

IsIn<T>(T, IEnumerable<T>)

Determina se uma sequência contém um dos elementos especificados em values.

[Extension]
public static bool IsIn<T>(this T source, IEnumerable<T> values)

Parameters

Nome Tipo Descrição
source T
values IEnumerable<T>

Returns

bool

Type Parameters

T

IsIn<T>(T, IEqualityComparer<T>, params T[])

Determina se uma sequência contém um dos elementos especificados, usando um comparador IEqualityComparer<T>.

[Extension]
public static bool IsIn<T>(this T source, IEqualityComparer<T> comparer, params T[] args)

Parameters

Nome Tipo Descrição
source T
comparer IEqualityComparer<T>
args T[]

Returns

bool

Type Parameters

T

IsIn<T>(T, params T[])

Determina se uma sequência contém um dos elementos especificados usando o comparador de igualdade padrão.

[Extension]
public static bool IsIn<T>(this T source, params T[] args)

Parameters

Nome Tipo Descrição
source T
args T[]

Returns

bool

Type Parameters

T

IsIncluded(AuthorizationMethods, params AuthorizationMethods[])

Whether the item is included in the list

[Extension]
public static bool IsIncluded(this AuthorizationMethods valueItem, params AuthorizationMethods[] options)

Parameters

Nome Tipo Descrição
valueItem AuthorizationMethods
options AuthorizationMethods[]

Returns

bool

IsIncluded(AuthorizationStatus, params AuthorizationStatus[])

Whether the item is included in the list

[Extension]
public static bool IsIncluded(this AuthorizationStatus valueItem, params AuthorizationStatus[] options)

Parameters

Nome Tipo Descrição
valueItem AuthorizationStatus
options AuthorizationStatus[]

Returns

bool

IsIncluded(SerializerTypeEnum, params SerializerTypeEnum[])

Whether the item is included in the list

[Extension]
public static bool IsIncluded(this SerializerTypeEnum valueItem, params SerializerTypeEnum[] options)

Parameters

Nome Tipo Descrição
valueItem SerializerTypeEnum
options SerializerTypeEnum[]

Returns

bool

IsIncluded(char, params char[])

Whether the item is included in the list

[Extension]
public static bool IsIncluded(this char valueItem, params char[] options)

Parameters

Nome Tipo Descrição
valueItem char
options char[]

Returns

bool

IsIncluded(string, params string[])

Whether the item is included in the list

[Extension]
public static bool IsIncluded(this string valueItem, params string[] options)

Parameters

Nome Tipo Descrição
valueItem string
options string[]

Returns

bool

IsOnlyDigits(string)

If the string is composed only of characters that are contained in the group {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}

[Extension]
public static bool IsOnlyDigits(this string value)

Parameters

Nome Tipo Descrição
value string

Returns

bool

IsRequestAvailable(HttpContext)

[Extension]
public static bool IsRequestAvailable(this HttpContext context)

Parameters

Nome Tipo Descrição
context HttpContext

Returns

bool

IsResponseAvailable(HttpContext)

[Extension]
public static bool IsResponseAvailable(this HttpContext context)

Parameters

Nome Tipo Descrição
context HttpContext

Returns

bool

IsSimpleType(Type)

[Extension]
public static bool IsSimpleType(this Type myType)

Parameters

Nome Tipo Descrição
myType Type

Returns

bool

IsValidDateTime(DateTime)

[Extension]
public static bool IsValidDateTime(this DateTime value)

Parameters

Nome Tipo Descrição
value DateTime

Returns

bool

IsVoid(bool)

[Extension]
public static bool IsVoid(this bool lValor)

Parameters

Nome Tipo Descrição
lValor bool

Returns

bool

IsVoid(byte)

If is equal to Byte.MinValue or nothing

[Extension]
public static bool IsVoid(this byte expression)

Parameters

Nome Tipo Descrição
expression byte

Returns

bool

IsVoid(byte[])

If the array is nothing or is empty or all elements in the list are equal to Byte.MinValue

[Extension]
public static bool IsVoid(this byte[] expression)

Parameters

Nome Tipo Descrição
expression byte[]

Returns

bool

IsVoid(char)

If is empty or nothing

[Extension]
public static bool IsVoid(this char expression)

Parameters

Nome Tipo Descrição
expression char

Returns

bool

IsVoid(IDictionary)

If the list is empty or nothing not the itens in itself

[Extension]
public static bool IsVoid(this IDictionary value)

Parameters

Nome Tipo Descrição
value IDictionary

Returns

bool

IsVoid(IEnumerable)

If the list is empty or nothing not the itens in itself

[Extension]
public static bool IsVoid(this IEnumerable list)

Parameters

Nome Tipo Descrição
list IEnumerable

Returns

bool

IsVoid(IList)

If the list is empty or nothing not the itens in itself

[Extension]
public static bool IsVoid(this IList list)

Parameters

Nome Tipo Descrição
list IList

Returns

bool

IsVoid(DBNull)

[Extension]
public static bool IsVoid(this DBNull expression)

Parameters

Nome Tipo Descrição
expression DBNull

Returns

bool

IsVoid(DataTable)

[Extension]
public static bool IsVoid(this DataTable source)

Parameters

Nome Tipo Descrição
source DataTable

Returns

bool

IsVoid(DateTime)

If is empty or nothing or if the date part is equal to Utils.Dates.MinBusinessDate.Date

[Extension]
public static bool IsVoid(this DateTime value)

Parameters

Nome Tipo Descrição
value DateTime

Returns

bool

IsVoid(decimal)

If is equal to zero or nothing

[Extension]
public static bool IsVoid(this decimal expression)

Parameters

Nome Tipo Descrição
expression decimal

Returns

bool

IsVoid(double)

If is equal to zero or nothing

[Extension]
public static bool IsVoid(this double expression)

Parameters

Nome Tipo Descrição
expression double

Returns

bool

IsVoid(int)

If is equal to zero or nothing

[Extension]
public static bool IsVoid(this int expression)

Parameters

Nome Tipo Descrição
expression int

Returns

bool

IsVoid(long)

If is equal to zero or nothing

[Extension]
public static bool IsVoid(this long expression)

Parameters

Nome Tipo Descrição
expression long

Returns

bool

IsVoid(string)

If is empty or nothing

[Extension]
public static bool IsVoid(this string expression)

Parameters

Nome Tipo Descrição
expression string

Returns

bool

IsVoid(string[])

If the list is empty or nothing not the itens in itself

[Extension]
public static bool IsVoid(this string[] expression)

Parameters

Nome Tipo Descrição
expression string[]

Returns

bool

IsVoid(StringBuilder)

[Extension]
public static bool IsVoid(this StringBuilder expression)

Parameters

Nome Tipo Descrição
expression StringBuilder

Returns

bool

JsonIsVoid(string)

If is empty or nothing

[Extension]
public static bool JsonIsVoid(this string expression)

Parameters

Nome Tipo Descrição
expression string

Returns

bool

NotHaveItens<T>(IEnumerable<T>)

Verify if the source is null or if not have values.

[Extension]
public static bool NotHaveItens<T>(this IEnumerable<T> source)

Parameters

Nome Tipo Descrição
source IEnumerable<T>

Returns

bool

Type Parameters

T

PadLeft(string, int, string)

[Extension]
public static string PadLeft(this string value, int lenght, string fillCaracter = " ")

Parameters

Nome Tipo Descrição
value string
lenght int
fillCaracter string

Returns

string

PadRight(string, int, string)

[Extension]
public static string PadRight(this string value, int lenght, string fillCaracter = " ")

Parameters

Nome Tipo Descrição
value string
lenght int
fillCaracter string

Returns

string

PathCombine(string, string)

[Extension]
public static string PathCombine(this string path1, string path2)

Parameters

Nome Tipo Descrição
path1 string
path2 string

Returns

string

RemoveBrackets(string)

Remove [ ... ] from each element that the string contains, for example '[test]' will be 'test' and '[alias].[test]' will be 'alias.test'

[Extension]
public static string RemoveBrackets(this string value)

Parameters

Nome Tipo Descrição
value string

Returns

string

RemoveDuplicates<T>(IEnumerable<T>)

Removes duplicate entries from a sequence of elements by comparing them using the Equals method. Provides an alternative to the Distinct method, which compares elements using their GetHashCode method.

[Extension]
public static IEnumerable<T> RemoveDuplicates<T>(this IEnumerable<T> source)

Parameters

Nome Tipo Descrição
source IEnumerable<T>

The sequence of elements to filter.

Returns

IEnumerable<T>

The original sequence with duplicate entries removed.

Type Parameters

T

The type of the elements of the sequence.

RemoveDuplicates<T>(IEnumerable<T>, Func<T, T, bool>)

Removes duplicate entries from a sequence of elements by using the specified Func to compare elements and determine whether they are equal. Provides an alternative to the Distinct method, which compares elements using their GetHashCode method.

[Extension]
public static IEnumerable<T> RemoveDuplicates<T>(this IEnumerable<T> source, Func<T, T, bool> equater)

Parameters

Nome Tipo Descrição
source IEnumerable<T>

The sequence of elements to filter.

equater Func<T, T, bool>

A Func that takes 2 elements of type T and returns true if they are equal, else false.

Returns

IEnumerable<T>

The original sequence with duplicate entries removed.

Type Parameters

T

The type of the elements of the sequence.

RemoveFirstAlias(string)

Remove brackets and the first alias

[Extension]
public static string RemoveFirstAlias(this string value)

Parameters

Nome Tipo Descrição
value string

Returns

string

Remarks

'[test]' will be 'test' and '[alias].[test]' will be 'test' and '[alias].[second].[test]' will be 'second.test'

RemoveSQLInvalidChars(string)

Remove chars SQL Injection

[Extension]
public static string RemoveSQLInvalidChars(this string expression)

Parameters

Nome Tipo Descrição
expression string

Returns

string

ReplaceWhenTagged<T>(List<string>, string, T, T)

By default when fieldsTagged is empty we always replace

[Extension]
public static T ReplaceWhenTagged<T>(this List<string> fieldsTagged, string fieldName, T valueToReplace, T valueToFaulBack)

Parameters

Nome Tipo Descrição
fieldsTagged List<string>
fieldName string
valueToReplace T
valueToFaulBack T

Returns

T

Type Parameters

T

RoundAwayZero(decimal)

Round using MidpointRounding.AwayFromZero

[Extension]
public static decimal RoundAwayZero(this decimal value)

Parameters

Nome Tipo Descrição
value decimal

Returns

decimal

Remarks

1.4 = 1 ; 1.5 = 2

RoundAwayZero(decimal, int)

Round using MidpointRounding.AwayFromZero

[Extension]
public static decimal RoundAwayZero(this decimal value, int decimals)

Parameters

Nome Tipo Descrição
value decimal
decimals int

Returns

decimal

Remarks

using one decimal 1.44 = 1.4 ; 1.45 = 1.5

RoundAwayZero(double)

Round using MidpointRounding.AwayFromZero

[Extension]
public static double RoundAwayZero(this double value)

Parameters

Nome Tipo Descrição
value double

Returns

double

Remarks

1.4 = 1 ; 1.5 = 2

RoundAwayZero(double, int)

Round using MidpointRounding.AwayFromZero

[Extension]
public static double RoundAwayZero(this double value, int decimals)

Parameters

Nome Tipo Descrição
value double
decimals int

Returns

double

Remarks

using one decimal 1.44 = 1.4 ; 1.45 = 1.5

SafeStartNew(TaskFactory, IWSContext, Action)

[Extension]
public static Task SafeStartNew(this TaskFactory factory, IWSContext context, Action actionItem)

Parameters

Nome Tipo Descrição
factory TaskFactory
context IWSContext
actionItem Action

Returns

Task

SafeStartNew(TaskFactory, Action)

[Extension]
public static Task SafeStartNew(this TaskFactory factory, Action actionItem)

Parameters

Nome Tipo Descrição
factory TaskFactory
actionItem Action

Returns

Task

SafeStartNew<T>(TaskFactory, IWSContext, Func<T>)

[Extension]
public static Task<T> SafeStartNew<T>(this TaskFactory factory, IWSContext context, Func<T> actionItem)

Parameters

Nome Tipo Descrição
factory TaskFactory
context IWSContext
actionItem Func<T>

Returns

Task<T>

Type Parameters

T

SafeStartNew<T>(TaskFactory, Func<T>)

[Extension]
public static Task<T> SafeStartNew<T>(this TaskFactory factory, Func<T> actionItem)

Parameters

Nome Tipo Descrição
factory TaskFactory
actionItem Func<T>

Returns

Task<T>

Type Parameters

T

SerialtoDate(string)

Convert a serial string date yyyyMMdd into a datetime object but only the date

[Extension]
public static DateTime SerialtoDate(this string sDate)

Parameters

Nome Tipo Descrição
sDate string

Returns

DateTime

SplitWithOutEmptyEntries(string, params char[])

Retorna uma matriz de cadeia de caracteres que contém as subcadeias nesta cadeia que são delimitadas por elementos de uma matriz de caracteres Unicode especificada e não retornam elementos de matriz vazia..

[Extension]
public static string[] SplitWithOutEmptyEntries(this string source, params char[] separator)

Parameters

Nome Tipo Descrição
source string

Texto que vai ser separada

separator char[]

Uma matriz de caracteres Unicode que delimitam as substrings nesta cadeia, uma matriz vazia que não contém delimitadores ou nula.

Returns

string[]

Retorna um vetor de strings

StartOfMonthDate(DateTime)

[Extension]
public static DateTime StartOfMonthDate(this DateTime value)

Parameters

Nome Tipo Descrição
value DateTime

Returns

DateTime

SubStringX(string, int, int)

This function is immune to the fact that the sum of Start + Length can be greater than the Lengh of the variable, and does not raise the exception ArgumentOutOfRangeException

[Extension]
public static string SubStringX(this string text, int start, int length = -1)

Parameters

Nome Tipo Descrição
text string
start int

The zero-based starting character position of a substring in this instance.

length int

The number of characters in the substring.

Returns

string

A string that is equivalent to the substring of length, length that begins at startIndex in this instance, or Empty if startIndex is equal to the length of this instance and length is zero.

Remarks

This method does not modify the value of the current instance. Instead, it returns a new string with length characters starting from the startIndex position in the current string.

ThisItem<TSource>(TSource)

[Extension]
public static TSource ThisItem<TSource>(this TSource source)

Parameters

Nome Tipo Descrição
source TSource

Returns

TSource

Type Parameters

TSource

ToBoolean(decimal)

[Extension]
public static bool ToBoolean(this decimal value)

Parameters

Nome Tipo Descrição
value decimal

Returns

bool

ToBoolean(double)

[Extension]
public static bool ToBoolean(this double value)

Parameters

Nome Tipo Descrição
value double

Returns

bool

ToBoolean(int)

[Extension]
public static bool ToBoolean(this int value)

Parameters

Nome Tipo Descrição
value int

Returns

bool

ToBoolean(string)

Convert the caracter into the boolean equivalent

[Extension]
public static bool ToBoolean(this string lValor)

Parameters

Nome Tipo Descrição
lValor string

Returns

bool

Remarks

{"S", "T", "Y", "1"} = True ; {"N", "F", "0"} = False ; other = False

ToCarater(bool)

[Extension]
public static string ToCarater(this bool lValor)

Parameters

Nome Tipo Descrição
lValor bool

Returns

string

ToCarater(DateTime)

[Extension]
public static string ToCarater(this DateTime dDate)

Parameters

Nome Tipo Descrição
dDate DateTime

Returns

string

ToCarater(DateTime, string)

[Extension]
public static string ToCarater(this DateTime dDate, string sFormat)

Parameters

Nome Tipo Descrição
dDate DateTime
sFormat string

Returns

string

ToDate(string)

Convert a string into a datetime object but only the date

[Extension]
public static DateTime ToDate(this string sDate)

Parameters

Nome Tipo Descrição
sDate string

Returns

DateTime

Remarks

It use the auto formats {"dd.MM.yyyy HH:mm:ss", "yyyy.MM.dd HH:mm:ss", "MM.dd.yyyy HH:mm:ss"} with any separator only on the date part, the hour is mandatory ':' separator

ToDateTime(double)

[Extension]
public static DateTime ToDateTime(this double time)

Parameters

Nome Tipo Descrição
time double

Returns

DateTime

ToDateTime(string)

Convert a string into a datetime object

[Extension]
public static DateTime ToDateTime(this string sDate)

Parameters

Nome Tipo Descrição
sDate string

Returns

DateTime

Remarks

It use the auto formats {"dd.MM.yyyy HH:mm:ss", "yyyy.MM.dd HH:mm:ss", "MM.dd.yyyy HH:mm:ss"} with any separator only on the date part, the hour is mandatory ':' separator

ToDecimal(string, ref bool)

[Extension]
public static decimal ToDecimal(this string value, ref bool lError = false)

Parameters

Nome Tipo Descrição
value string
lError bool

Returns

decimal

ToDigit(bool)

[Extension]
public static string ToDigit(this bool lValor)

Parameters

Nome Tipo Descrição
lValor bool

Returns

string

ToDouble(string, ref bool)

[Extension]
public static double ToDouble(this string value, ref bool lError = false)

Parameters

Nome Tipo Descrição
value string
lError bool

Returns

double

ToExtensoPt(int)

Converter para extenso um número inteiro

[Extension]
public static string ToExtensoPt(this int number)

Parameters

Nome Tipo Descrição
number int

Returns

string

ToHourAndMinutes(DateTime)

[Extension]
public static string ToHourAndMinutes(this DateTime tDateTime)

Parameters

Nome Tipo Descrição
tDateTime DateTime

Returns

string

ToHourAndMinutesSerial(DateTime)

[Extension]
public static string ToHourAndMinutesSerial(this DateTime tDateTime)

Parameters

Nome Tipo Descrição
tDateTime DateTime

Returns

string

ToHourMinutes(string)

Get only the hours and minutes os the string, the result it's always size 5

[Extension]
public static string ToHourMinutes(this string cTime)

Parameters

Nome Tipo Descrição
cTime string

Returns

string

Remarks

2 will be 02:00 ; 12 will be 12:00 ; 12.3 will be 12:03 ; 12/3 will be 12:03 ; 12.31 will be 12:31 ; 12/31 will be 12:31

ToISO(DateTime)

[Extension]
public static string ToISO(this DateTime dDate)

Parameters

Nome Tipo Descrição
dDate DateTime

Returns

string

ToISO2(DateTime)

[Extension]
public static string ToISO2(this DateTime dDate)

Parameters

Nome Tipo Descrição
dDate DateTime

Returns

string

ToISO3(DateTime)

[Extension]
public static string ToISO3(this DateTime dDate)

Parameters

Nome Tipo Descrição
dDate DateTime

Returns

string

ToInteger(char)

[Extension]
public static int ToInteger(this char source)

Parameters

Nome Tipo Descrição
source char

Returns

int

ToInteger(decimal)

[Extension]
public static int ToInteger(this decimal source)

Parameters

Nome Tipo Descrição
source decimal

Returns

int

ToInteger(double)

[Extension]
public static int ToInteger(this double source)

Parameters

Nome Tipo Descrição
source double

Returns

int

ToInteger(string, ref bool)

[Extension]
public static int ToInteger(this string value, ref bool lError = false)

Parameters

Nome Tipo Descrição
value string
lError bool

Returns

int

ToJoinString(IEnumerable<string>, string)

[Extension]
public static string ToJoinString(this IEnumerable<string> source, string separator)

Parameters

Nome Tipo Descrição
source IEnumerable<string>
separator string

Returns

string

ToList<TSource, TOutput>(IEnumerable<TSource>, Func<TSource, TOutput>)

[Extension]
public static List<TOutput> ToList<TSource, TOutput>(this IEnumerable<TSource> source, Func<TSource, TOutput> addItemFunction)

Parameters

Nome Tipo Descrição
source IEnumerable<TSource>
addItemFunction Func<TSource, TOutput>

Returns

List<TOutput>

Type Parameters

TSource
TOutput

ToSerial(DateTime)

Convert a datetime object to the serial string but obly the date part

[Extension]
public static string ToSerial(this DateTime dDate)

Parameters

Nome Tipo Descrição
dDate DateTime

Returns

string

ToStr(decimal)

[Extension]
public static string ToStr(this decimal expression)

Parameters

Nome Tipo Descrição
expression decimal

Returns

string

ToStr(double)

[Extension]
public static string ToStr(this double expression)

Parameters

Nome Tipo Descrição
expression double

Returns

string

ToStr(int)

[Extension]
public static string ToStr(this int expression)

Parameters

Nome Tipo Descrição
expression int

Returns

string

ToTime(DateTime)

[Extension]
public static string ToTime(this DateTime tDateTime)

Parameters

Nome Tipo Descrição
tDateTime DateTime

Returns

string

ToTimeZoneDate(DateTime)

Mark as UTC and return only the date part

[Extension]
public static DateTime ToTimeZoneDate(this DateTime dataItem)

Parameters

Nome Tipo Descrição
dataItem DateTime

Returns

DateTime

ToTimeZoneDate(string)

Convert a string to a datetime object only the date part anda mark as UTC

[Extension]
public static DateTime ToTimeZoneDate(this string dt)

Parameters

Nome Tipo Descrição
dt string

Returns

DateTime

ToTimeZoneDateTime(DateTime)

Mark as UTC

[Extension]
public static DateTime ToTimeZoneDateTime(this DateTime dt)

Parameters

Nome Tipo Descrição
dt DateTime

Returns

DateTime

ToType<TResult>(object)

[Extension]
public static TResult ToType<TResult>(this object source)

Parameters

Nome Tipo Descrição
source object

Returns

TResult

Type Parameters

TResult

Truncate(decimal, int)

[Extension]
public static decimal Truncate(this decimal value, int decimalPlaces)

Parameters

Nome Tipo Descrição
value decimal
decimalPlaces int

Returns

decimal

UpperAlltrim(string)

[Extension]
public static string UpperAlltrim(this string expression)

Parameters

Nome Tipo Descrição
expression string

Returns

string

WeekNumber(DateTime)

[Extension]
public static int WeekNumber(this DateTime value)

Parameters

Nome Tipo Descrição
value DateTime

Returns

int