Table of Contents

Class ListExtensions

Namespace
Tripous
Assembly
Tripous.dll

Extensions

public static class ListExtensions
Inheritance
ListExtensions
Inherited Members

Methods

AsArray(IList)

Returns the content of List as an object array.

public static object[] AsArray(this IList List)

Parameters

List IList

Returns

object[]

AsTextLines(IList<string>)

Returns the content of a generic string list as a string

public static string AsTextLines(this IList<string> List)

Parameters

List IList<string>

Returns

string

CanMove(IList, int, bool)

Returns true if item can change position.

NOTE: Down = true means towards to 0, where false means towards to List.Count

public static bool CanMove(this IList List, int Index, bool Down)

Parameters

List IList
Index int
Down bool

Returns

bool

CanMove(IList, object, bool)

Returns true if item can change position.

public static bool CanMove(this IList List, object Obj, bool Down)

Parameters

List IList
Obj object
Down bool

Returns

bool

CommaText(IList<string>, bool)

Gets the whole content of the List as a single line of text, where each line ends with a comma (,)

public static string CommaText(this IList<string> List, bool WithLineBreaks = false)

Parameters

List IList<string>
WithLineBreaks bool

Returns

string

ContainsText(IList<string>, string)

Returns trur if Value exists in List, case insensitively.

public static bool ContainsText(this IList<string> List, string Value)

Parameters

List IList<string>
Value string

Returns

bool

Exchange(IList, int, int)

Exchanges source to source positions.

public static void Exchange(this IList List, int SourceIndex, int DestIndex)

Parameters

List IList
SourceIndex int
DestIndex int

Exchange(IList, object, object)

Exchanges source to source positions.

public static void Exchange(this IList List, object Source, object Dest)

Parameters

List IList
Source object
Dest object

GetKeyValuesList(IList<object>, int, bool)

Used in constructing SQL statements that contain a WHERE clause of the type

where FIELD_NAME in (...)

This method limits the number of elements inside the in (...) according to the passed in ModValue, in order to avoid problems with database servers that have such a limit.

It returns a string array where each element contains no more than ModValue values from SourceList.

public static string[] GetKeyValuesList(this IList<object> SourceList, int ModValue, bool DiscardBelowZeroes)

Parameters

SourceList IList<object>
ModValue int
DiscardBelowZeroes bool

Returns

string[]

GetKeyValuesList(IList<object>, string, int, bool)

Used in constructing SQL statements that contain a WHERE clause of the type

where FIELD_NAME in (...)

This method limits the number of elements inside the in (...) according to the passed in ModValue, in order to avoid problems with database servers that have such a limit.

It returns a string array where each element contains no more than ModValue values from SourceList.

public static string[] GetKeyValuesList(this IList<object> SourceList, string FieldName, int ModValue, bool DiscardBelowZeroes)

Parameters

SourceList IList<object>
FieldName string
ModValue int
DiscardBelowZeroes bool

Returns

string[]

IndexOfText(IList<string>, string)

Returns the index of Value in List, case insensitively, if exists, else -1.

public static int IndexOfText(this IList<string> List, string Value)

Parameters

List IList<string>
Value string

Returns

int

IsValidIndex(IList, int)

Returns true if Index is in the range 0..List.Count - 1

public static bool IsValidIndex(this IList List, int Index)

Parameters

List IList
Index int

Returns

bool

LoadFromFile(IList, string)

Loads List from FileName

public static void LoadFromFile(this IList List, string FileName)

Parameters

List IList
FileName string

Move(IList, int, bool)

Moves item a position up or down. Returns true if item can change position.

public static bool Move(this IList List, int Index, bool Down)

Parameters

List IList
Index int
Down bool

Returns

bool

Move(IList, object, bool)

Moves item a position up or down. Returns true if item can change position.

public static bool Move(this IList List, object Obj, bool Down)

Parameters

List IList
Obj object
Down bool

Returns

bool

SaveToFile(IList, string)

Saves List to FileName

public static void SaveToFile(this IList List, string FileName)

Parameters

List IList
FileName string

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

Splits a sequence into chunks of a defined size.

int[] numbers = { 1, 2, 3, 4, 5, 6, 7 };
var NumberLists = Split(numbers, 3);        // results in 3 lists as {1, 2, 3}, {4, 5, 6}, {7}
public static List<List<T>> Split<T>(this IEnumerable<T> Source, int ChunkSize)

Parameters

Source IEnumerable<T>
ChunkSize int

Returns

List<List<T>>

Type Parameters

T

ToDataTable<T>(IList<T>)

Converts a generic list to DataTable.

Property names of the list element type become column names in the DataTable.

public static DataTable ToDataTable<T>(this IList<T> SourceList)

Parameters

SourceList IList<T>

Returns

DataTable

Type Parameters

T

ToDictionary(IList<string>)

Returns a specified string list as a dictionary.

Each string in the list must contain an equal sign character, e.g. Key=Value, for this to succeed.

public static Dictionary<string, string> ToDictionary(this IList<string> SourceList)

Parameters

SourceList IList<string>

Returns

Dictionary<string, string>