Table of Contents

Class Utils

Namespace
Common
Assembly
Lykke.Common.dll
public static class Utils
Inheritance
Utils
Inherited Members

Fields

IsoDateMask

public const string IsoDateMask = "yyyy-MM-dd"

Field Value

string

IsoDateTimeMask

public const string IsoDateTimeMask = "yyyy-MM-dd HH:mm:ss"

Field Value

string

RussianDateMask

public const string RussianDateMask = "dd.MM.yyyy"

Field Value

string

Methods

AreSame(List<byte>, byte[], int)

Check the equality of two sequences starting from the specified index of the first.

public static bool AreSame(List<byte> src, byte[] search, int indexOf)

Parameters

src List<byte>

The string where to search.

search byte[]

The string which to look for.

indexOf int

The index in src string to start searching from.

Returns

bool

Base64ToString(string)

public static string Base64ToString(this string src)

Parameters

src string

Returns

string

ByteToHex(byte)

public static string ByteToHex(byte src)

Parameters

src byte

Returns

string

CloneDictionary<TKey, TValue>(Dictionary<TKey, TValue>)

[Obsolete("Use Dictionary constructor")]
public static Dictionary<TKey, TValue> CloneDictionary<TKey, TValue>(this Dictionary<TKey, TValue> src)

Parameters

src Dictionary<TKey, TValue>

Returns

Dictionary<TKey, TValue>

Type Parameters

TKey
TValue

CloneDoubleDictionary<TKey, TKey2, TValue>(Dictionary<TKey, Dictionary<TKey2, TValue>>)

public static Dictionary<TKey, Dictionary<TKey2, TValue>> CloneDoubleDictionary<TKey, TKey2, TValue>(this Dictionary<TKey, Dictionary<TKey2, TValue>> src)

Parameters

src Dictionary<TKey, Dictionary<TKey2, TValue>>

Returns

Dictionary<TKey, Dictionary<TKey2, TValue>>

Type Parameters

TKey
TKey2
TValue

CombineString(IEnumerable<string>, char)

public static string CombineString(IEnumerable<string> strings, char separator)

Parameters

strings IEnumerable<string>
separator char

Returns

string

CutFrom<T>(IEnumerable<T>, int, int)

[Obsolete("Use MoreLinq Slice extension method")]
public static IEnumerable<T> CutFrom<T>(this IEnumerable<T> src, int from, int length)

Parameters

src IEnumerable<T>
from int
length int

Returns

IEnumerable<T>

Type Parameters

T

Enumerate<T>()

public static IEnumerable<T> Enumerate<T>()

Returns

IEnumerable<T>

Type Parameters

T

GenderAmount(int, string, string, string)

public static string GenderAmount(int amount, string oneWord, string twoWord, string fiveOrZerosWord)

Parameters

amount int
oneWord string
twoWord string
fiveOrZerosWord string

Returns

string

GenerateInts(int, int)

[Obsolete("Use Enumerable Range method")]
public static IEnumerable<int> GenerateInts(int from, int to)

Parameters

from int
to int

Returns

IEnumerable<int>

GeneratePassword()

public static string GeneratePassword()

Returns

string

GenerateRandomBytes(int)

public static byte[] GenerateRandomBytes(int length)

Parameters

length int

Returns

byte[]

GenerateYearsTillNow(int)

public static int[] GenerateYearsTillNow(int fromYear)

Parameters

fromYear int

Returns

int[]

GetChangesInPercents(double, double)

public static double? GetChangesInPercents(double firstVal, double secondVal)

Parameters

firstVal double
secondVal double

Returns

double?

GetFixedAsString(decimal, int)

Formating float as string with fixed accuracy and '.' as separate

public static string GetFixedAsString(this decimal value, int accuracy)

Parameters

value decimal

float value

accuracy int

accuracy for value

Returns

string

GetFixedAsString(double, int)

Formating float as string with fixed accuracy and '.' as separate

public static string GetFixedAsString(this double value, int accuracy)

Parameters

value double

float value

accuracy int

accuracy for value

Returns

string

GetNextDateByDayOfTheWeek(DateTime, DayOfWeek)

Get the nearest date (in future) for the specified day of week, counting from the current date.

public static DateTime GetNextDateByDayOfTheWeek(DateTime nowDateTime, DayOfWeek dayOfWeek)

Parameters

nowDateTime DateTime

The current date.

dayOfWeek DayOfWeek

The target day of week.

Returns

DateTime

HexToArray(string)

public static byte[] HexToArray(string src)

Parameters

src string

Returns

byte[]

HexToByte(string)

public static byte HexToByte(string src)

Parameters

src string

Returns

byte

HexToString(string)

public static string HexToString(string value)

Parameters

value string

Returns

string

IndexOf(List<byte>, byte[])

public static int IndexOf(this List<byte> src, byte[] search)

Parameters

src List<byte>
search byte[]

Returns

int

IsSimpleType(Type)

public static bool IsSimpleType(this Type type)

Parameters

type Type

Returns

bool

Limit<T>(IEnumerable<T>, int)

[Obsolete("Use Enumerable Take method")]
public static IEnumerable<T> Limit<T>(this IEnumerable<T> src, int limit)

Parameters

src IEnumerable<T>
limit int

Returns

IEnumerable<T>

Type Parameters

T

ListsAreSame<T>(T[], T[], Func<T, T, bool>)

public static bool ListsAreSame<T>(T[] oldOne, T[] newOne, Func<T, T, bool> equal)

Parameters

oldOne T[]
newOne T[]
equal Func<T, T, bool>

Returns

bool

Type Parameters

T

LogPartFromStream(ILog, Stream, string, string, Exception)

public static Task LogPartFromStream(this ILog log, Stream stream, string component, string process, Exception ex)

Parameters

log ILog
stream Stream
component string
process string
ex Exception

Returns

Task

Map(IEnumerable<double>, double?, double?, double?, double?)

public static IEnumerable<double> Map(this IEnumerable<double> values, double? minFrom = null, double? maxFrom = null, double? minTo = null, double? maxTo = null)

Parameters

values IEnumerable<double>
minFrom double?
maxFrom double?
minTo double?
maxTo double?

Returns

IEnumerable<double>

Map(double, double, double, double, double)

public static double Map(this double value, double minFrom, double maxFrom, double minTo, double maxTo)

Parameters

value double
minFrom double
maxFrom double
minTo double
maxTo double

Returns

double

Mod10Check(string)

public static bool Mod10Check(string creditCardNumber)

Parameters

creditCardNumber string

Returns

bool

NumberToWords(int)

public static string NumberToWords(int number)

Parameters

number int

Returns

string

NumberToWordsRus(int, bool)

public static string NumberToWordsRus(int amount, bool ismale)

Parameters

amount int
ismale bool

Returns

string

ParamsToString(object)

public static string ParamsToString(object obj)

Parameters

obj object

Returns

string

ParseAnyDecimal(string)

public static decimal ParseAnyDecimal(this string amount)

Parameters

amount string

Returns

decimal

ParseAnyDecimalOrDefault(string, decimal)

public static decimal ParseAnyDecimalOrDefault(this string amount, decimal defaultValue)

Parameters

amount string
defaultValue decimal

Returns

decimal

ParseAnyDouble(string)

public static double ParseAnyDouble(this string amount)

Parameters

amount string

Returns

double

ParseAnyDoubleOrDefault(string, double)

public static double ParseAnyDoubleOrDefault(this string amount, double defaultValue)

Parameters

amount string
defaultValue double

Returns

double

ParseEnum<T>(string)

public static T ParseEnum<T>(this string value)

Parameters

value string

Returns

T

Type Parameters

T

ParseEnum<T>(string, T)

public static T ParseEnum<T>(this string value, T defaultValue)

Parameters

value string
defaultValue T

Returns

T

Type Parameters

T

ParseIntOrDefault(string, int)

public static int ParseIntOrDefault(this string amount, int defaultValue)

Parameters

amount string
defaultValue int

Returns

int

ParseIpEndPoint(string)

public static IPEndPoint ParseIpEndPoint(this string src)

Parameters

src string

Returns

IPEndPoint

PutLastSymbol(string, char)

public static string PutLastSymbol(string src, char symbol)

Parameters

src string
symbol char

Returns

string

SetNewTime(DateTime, string)

public static DateTime SetNewTime(DateTime dateTime, string time)

Parameters

dateTime DateTime
time string

Returns

DateTime

SkipEvenly<T>(IEnumerable<T>, int)

public static IEnumerable<T> SkipEvenly<T>(this IEnumerable<T> initialEnumerable, int newSize)

Parameters

initialEnumerable IEnumerable<T>
newSize int

Returns

IEnumerable<T>

Type Parameters

T

StringToHex(string)

public static string StringToHex(this string src)

Parameters

src string

Returns

string

ToBase64(byte[])

public static string ToBase64(this byte[] src)

Parameters

src byte[]

Returns

string

ToBase64(string)

public static string ToBase64(this string src)

Parameters

src string

Returns

string

ToByte(bool)

public static byte ToByte(this bool src)

Parameters

src bool

Returns

byte

ToBytes(Stream)

public static byte[] ToBytes(this Stream src)

Parameters

src Stream

Returns

byte[]

ToBytesAsync(Stream)

public static Task<byte[]> ToBytesAsync(this Stream src)

Parameters

src Stream

Returns

Task<byte[]>

ToChunks<T>(IEnumerable<T>, int)

[Obsolete("Use MoreLinq Batch extension method")]
public static IEnumerable<IEnumerable<T>> ToChunks<T>(this IEnumerable<T> src, int chunkSize)

Parameters

src IEnumerable<T>
chunkSize int

Returns

IEnumerable<IEnumerable<T>>

Type Parameters

T

ToHexString(ICollection<byte>)

public static string ToHexString(this ICollection<byte> src)

Parameters

src ICollection<byte>

Returns

string

ToPieces<T>(IEnumerable<T>, int)

[Obsolete("Use MoreLinq Batch method")]
public static IEnumerable<IEnumerable<T>> ToPieces<T>(this IEnumerable<T> src, int countInPicese)

Parameters

src IEnumerable<T>
countInPicese int

Returns

IEnumerable<IEnumerable<T>>

Type Parameters

T

ToSortedDictionary<TKey, TValue>(IEnumerable<TValue>, Func<TValue, TKey>)

public static SortedDictionary<TKey, TValue> ToSortedDictionary<TKey, TValue>(this IEnumerable<TValue> src, Func<TValue, TKey> getKey)

Parameters

src IEnumerable<TValue>
getKey Func<TValue, TKey>

Returns

SortedDictionary<TKey, TValue>

Type Parameters

TKey
TValue

ToStream(byte[])

public static Stream ToStream(this byte[] src)

Parameters

src byte[]

Returns

Stream

ToStream(string)

public static MemoryStream ToStream(this string src)

Parameters

src string

Returns

MemoryStream

ToUtf8Bytes(string)

public static byte[] ToUtf8Bytes(this string src)

Parameters

src string

Returns

byte[]

TruncateDecimalPlaces(decimal, int, bool)

public static decimal TruncateDecimalPlaces(this decimal value, int places, bool toUpper = false)

Parameters

value decimal
places int
toUpper bool

Returns

decimal

TruncateDecimalPlaces(double, int, bool)

public static double TruncateDecimalPlaces(this double value, int places, bool toUpper = false)

Parameters

value double
places int
toUpper bool

Returns

double